天天看点

QTableView表头添加CheckBox

class HeaderView : public QHeaderView
{
    Q_OBJECT

public:
    explicit HeaderView(Qt::Orientation orientation, QWidget* parent = 0)
        : QHeaderView(orientation, parent) 
    {
        cbx_header= new QCheckBox(this);
        cbx_header->setVisible(true);
    }

protected:
    void updateGeometries() 
    {
        cbx_header->move(sectionPosition(0) + 3, 6);
    }

private:
    QCheckBox *cbx_header;    
};      
QTableView *tmp_tableview;
tmp_tableview = new QTableView();
tmp_tableview->setRowCount(3);
tmp_tableview->setColumnCount(4);

HeaderView* header = new HeaderView(Qt::Horizontal, tmp_tableview);
tmp_tableview->setHorizontalHeader(header);
tmp_tableview->show();