QT 在tableview表头添加复选框
上一篇已经在第一列中添加了复选框,本篇实在表头添加复选框并对其信号与槽进行关联,基本都是把别人的代码拿过来改改
https://blog.csdn.net/qq_44257811/article/details/120266599
重写QHeaderView的方法painSection
class TableHeaderView:public QHeaderView
{
Q_OBJECT
public:
TableHeaderView(Qt::Orientation orientation, QWidget *parent);
~TableHeaderView();
public:
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
bool event(QEvent *e) Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
public slots:
void onStateChanged(int state);
signals:
void stateChanged(int state);
public:
bool m_bPressed;
bool m_bChecked;
bool m_bTristate;
bool m_bNoChange;
bool m_bMoving;
};
#define CHECK_BOX_COLUMN 0
#define File_PATH_COLUMN 1
TableHeaderView::TableHeaderView(Qt::Orientation orientation, QWidget *parent)
: