Advertisement

QTableWidget表头添加自定义复选框

阅读量:

关于

本文重点阐述了在QTableView表格组件中实现表头复选框添加的方法。通过查阅相关文档及网络资源,发现该功能无法直接配置,通常采用继承QHeaderView类的方式,并对paintSection方法进行重写,从而构建一个自定义的QHeaderView子类以达成目标。

子类头文件 HeaderView.h

源代码如下:

复制代码
    #ifndef HEADERVIEW_H
    #define HEADERVIEW_H
    
    #include <QObject>
    #include <QHeaderView>
    #include <QPainter>
    
    class HeaderView : public QHeaderView
    {
    public:
    //构造函数, 第一个参数设定表头方向
    HeaderView(Qt::Orientation orientation, QWidget* parent = 0);
    
    protected:
    void paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const;
    
    void mousePressEvent

全部评论 (0)

还没有任何评论哟~