C++ (Qt)class MyHeader : public QHeaderView{ Q_OBJECT//...//...//...protected: virtual void paintSection ( QPainter * painter, const QRect & rect, int logicalIndex ) const;}; static QPixmap drawCheckBox(QStyle* Style, QStyle::State State, const QWidget* w) { QStyleOptionButton StyleOptionButton; if(w) {StyleOptionButton.initFrom(w);} StyleOptionButton.state = State; QRect r = Style->subElementRect (QStyle::SE_CheckBoxIndicator, &StyleOptionButton); StyleOptionButton.rect = r; if(!(State&QStyle::State_Enabled)) { QPalette p = QApplication::palette(); p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Disabled, QPalette::Text)); StyleOptionButton.palette = p; } QPixmap pixmap(r.width(), r.height()); pixmap.fill(Qt::transparent); QPainter painter; painter.begin(&pixmap); painter.translate(-r.left(), -r.top()); Style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &StyleOptionButton, &painter); painter.end(); return pixmap;} void MyHeader::paintSection ( QPainter * painter, const QRect & rect, int logicalIndex ) const { // QHeaderView::paintSection(painter, rect, logicalIndex); QPixmap pm = drawCheckBox(QApplication::style(), QStyle::State_Active | QStyle::State_Enabled | QStyle::State_On, this); QRect DstRect = pm.rect(); int woffset = rect.left() + (rect.width()-pm.rect().width())/2; int hoffset = rect.top() + (rect.height()-pm.rect().height())/2; DstRect.translate(woffset, hoffset); painter->drawPixmap(DstRect, pm, pm.rect()); }
C++ (Qt)QPixmap drawCheckBox(QStyle* Style, QStyle::State State, const QWidget* w) { QStyleOptionButton StyleOptionButton; if(w) {StyleOptionButton.initFrom(w);} StyleOptionButton.state = State; QRect r = Style->subElementRect (QStyle::SE_CheckBoxIndicator, &StyleOptionButton); StyleOptionButton.rect = r; if(!(State&QStyle::State_Enabled)) { QPalette p = QApplication::palette(); p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Disabled, QPalette::Text)); StyleOptionButton.palette = p; } QPixmap pixmap(r.width(), r.height()); pixmap.fill(Qt::transparent); QPainter painter; painter.begin(&pixmap); painter.translate(-r.left(), -r.top()); Style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &StyleOptionButton, &painter); painter.end(); return pixmap;} QPixmap Pixmap;Pixmap = drawCheckBox(Style, QStyle::State_Off);Pixmap = drawCheckBox(Style, QStyle::State_On);Pixmap = drawCheckBox(Style, QStyle::State_NoChange);Pixmap = drawCheckBox(Style, QStyle::State_Active | QStyle::State_Enabled | QStyle::State_Off );Pixmap = drawCheckBox(Style, QStyle::State_Active | QStyle::State_Enabled | QStyle::State_On);Pixmap = drawCheckBox(Style, QStyle::State_Active | QStyle::State_Enabled | QStyle::State_NoChange);Pixmap = drawCheckBox(Style, QStyle::State_Active | QStyle::State_Enabled | QStyle::State_Off | QStyle::State_MouseOver);Pixmap = drawCheckBox(Style, QStyle::State_Active | QStyle::State_Enabled | QStyle::State_On | QStyle::State_MouseOver);Pixmap = drawCheckBox(Style, QStyle::State_Active | QStyle::State_Enabled | QStyle::State_NoChange | QStyle::State_MouseOver);Pixmap = drawCheckBox(Style, QStyle::State_Active | QStyle::State_Enabled | QStyle::State_Off | QStyle::State_MouseOver | QStyle::State_Sunken);Pixmap = drawCheckBox(Style, QStyle::State_Active | QStyle::State_Enabled | QStyle::State_On | QStyle::State_MouseOver | QStyle::State_Sunken);Pixmap = drawCheckBox(Style, QStyle::State_Active | QStyle::State_Enabled | QStyle::State_NoChange | QStyle::State_MouseOver | QStyle::State_Sunken);