HI,
I am trying to use a style sheet to change a QStyleOptionButton to work as a QCheckBox but display with my own checked/unchecked indicators. I have had success setting the stylesheet on normal checkboxes but in this case I need to use a QStyleOptionButton and this doesnt seem to work? My code is as follows:
//m_checkBoxRect is previously setup
m_checkboxRect.setY(rect.height() / 2 - m_checkboxRect.height() / 2);
styledCheckBox->setGeometry(m_checkboxRect);
styledCheckBox->setCheckState(m_checkboxState);
styledCheckBox->setStyleSheet(
"QCheckedBox::indicator:unchecked { image: url(:/Resources/indicator_off.png);}"
"QCheckedBox::indicator:checked { image: url(:/Resources/indicator_on.png);}"
"QCheckedBox::indicator:indeterminate { image: url(:/Resources/indicator_partial.png);}"
);
option.initFrom(styledCheckBox);
option.rect = m_checkboxRect;
style
()->drawControl
(QStyle::CE_CheckBox,
&option, painter,
this);
QStyleOptionButton option;
//m_checkBoxRect is previously setup
m_checkboxRect.setY(rect.height() / 2 - m_checkboxRect.height() / 2);
QCheckBox* styledCheckBox = new QCheckBox();
styledCheckBox->setGeometry(m_checkboxRect);
styledCheckBox->setCheckState(m_checkboxState);
styledCheckBox->setStyleSheet(
"QCheckedBox::indicator:unchecked { image: url(:/Resources/indicator_off.png);}"
"QCheckedBox::indicator:checked { image: url(:/Resources/indicator_on.png);}"
"QCheckedBox::indicator:indeterminate { image: url(:/Resources/indicator_partial.png);}"
);
option.initFrom(styledCheckBox);
option.rect = m_checkboxRect;
style()->drawControl(QStyle::CE_CheckBox, &option, painter, this);
To copy to clipboard, switch view to plain text mode
All I seem to get back is an unchecked checkbox which doesn't respond to my mouse presses.
Does anyone have any ideas as to why this wont work, or perhaps another route??
Bookmarks