zoukankan      html  css  js  c++  java
  • QTableWidget添加带有复选框的表头

    #ifndef SCHECKBOXHEADERVIEW_H
    #define SCHECKBOXHEADERVIEW_H
    #include <QtGui>
    #include <QPainter>
    #include <QHeaderView>
    #include <QStyleOptionButton>
    #include <QStyle>
    class SCheckBoxHeaderView : public QHeaderView
    {
        Q_OBJECT
    private:
        bool isChecked;
        int m_checkColIdx;
    public:
        SCheckBoxHeaderView( int checkColumnIndex, Qt::Orientation orientation, QWidget * parent = 0) :
        QHeaderView(orientation, parent) {
            m_checkColIdx = checkColumnIndex;
            isChecked = false;
        }
    signals:
        void checkStausChange(bool);
    protected:
        void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const {
            painter->save();
            QHeaderView::paintSection(painter, rect, logicalIndex);
            painter->restore();
            if (logicalIndex == m_checkColIdx) {
                QStyleOptionButton option;
                int width = 10;
                for (int i=0; i<logicalIndex; ++i)
                width += sectionSize( i );
                option.rect = QRect(3, 5, 21, 21);
                if (isChecked)
                    option.state = QStyle::State_On;
                else
                    option.state = QStyle::State_Off;
                this->style()->drawControl(QStyle::CE_CheckBox, &option, painter);
            }
        }
        void mousePressEvent(QMouseEvent *event) {
            if (visualIndexAt(event->pos().x()) == m_checkColIdx) {
                isChecked = !isChecked;
                this->updateSection(m_checkColIdx);
                emit checkStausChange(isChecked);
            }
            QHeaderView::mousePressEvent(event);
        }
    };
    #endif // SCHECKBOXHEADERVIEW_H
    ————————————————
    版权声明:本文为CSDN博主「沙振宇」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/u014597198/java/article/details/77579070

    m_checkHeader = new SCheckBoxHeaderView(0, Qt::Horizontal, this);
        this->setHorizontalHeader(m_checkHeader);   //  这个this指针的父为QTableWidget
        connect(m_checkHeader, &SCheckBoxHeaderView::checkStausChange, [=](bool check){
            qDebug() << "is:" <<check;
        });
    ————————————————
    版权声明:本文为CSDN博主「沙振宇」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/u014597198/java/article/details/77579070

  • 相关阅读:
    【原创】Apache ab结果参数详解
    【转载】QPS,用户平均等待时间,服务器平均请求处理时间
    【原创】Apache ab测试时出现:apr_socket_recv "connection reset by peer" 104
    【做题】Codeforces Round #429 (Div. 2) E. On the Bench——组合问题+dp
    oracle递归查询
    http1.0和1.1的区别
    here with you
    spring杂碎
    西海情歌
    //随机生成 10到20条数据 数据包含 用户名(5-10位的字母) 性别 年龄(1-100岁)
  • 原文地址:https://www.cnblogs.com/coolbear/p/12844367.html
Copyright © 2011-2022 走看看