CCustomSplitter效果如图:
///#include "MyCustomSplitter.h" 头文件
#ifndef MYSPLITTER_H
#define MYSPLITTER_H
#include <QToolButton>
//#include <QSplitterHandle>
#include <QSplitter>
enum SplitterHiddenDirection
{
SHD_None = 0,
SHD_Left,
SHD_Right,
SHD_Top,
SHD_Bottom
};
class CCustomSplitterHandle : public QSplitterHandle
{
Q_OBJECT
public:
CCustomSplitterHandle(Qt::Orientation o, SplitterHiddenDirection hsd, QSplitter *parent);
~CCustomSplitterHandle();
void setButtonChecked(bool checked);
signals:
void hideWidget(bool isHide);
public slots:
void onButtonclicked(bool checked);
private:
SplitterHiddenDirection m_enHiddenDirection;
QToolButton* m_pButton;
};
class CCustomSplitter : public QSplitter
{
Q_OBJECT
public:
CCustomSplitter(Qt::Orientation o, SplitterHiddenDirection shd, QWidget* parent = Q_NULLPTR);
void setHiddenDirection(SplitterHiddenDirection shd);
protected:
QSplitterHandle *createHandle();
public slots:
void onHideWidget(bool isHide);
void onSplitterMoved(int pos, int index);
private:
CCustomSplitterHandle* m_pSplitterHandle;
QByteArray m_oOldState;
SplitterHiddenDirection m_enHiddenDirection;
};
#endif
///#include "MyCustomSplitter.cpp" 源文件