我正在尝试仅更改QCheckBox
指示器矩形的颜色。
目前我成功绘制了矩形的右边和底线。可能我在这里做错了什么。
这是我的代码:
CheckBoxWidget.cpp
CheckBoxWidget::CheckBoxWidget(QObject *poParent)
: QItemDelegate(poParent)
{
}
void CheckBoxWidget::drawCheck( QPainter *painter,
const QStyleOptionViewItem &option,
const QRect & rect,
Qt::CheckState state) const
{
QRect oCheckBoxRect =
QApplication::style()->subElementRect( QStyle::SE_CheckBoxIndicator, &option);
painter->setPen(Qt::white);
painter->drawRect(oCheckBoxRect);
QItemDelegate::drawCheck(painter, option, oCheckBoxRect, state);
}
CheckBoxWidget.h
class CheckBoxWidget : public QItemDelegate
{
Q_OBJECT
public:
CheckBoxWidget(QObject *poParent = 0);
virtual ~CheckBoxWidget();
protected:
virtual void drawCheck( QPainter *painter,
const QStyleOptionViewItem &option,
const QRect &,
Qt::CheckState state) const;
};
有什么建议么 ?