I want to change the background color of my custom widget depending on the state of some property, but I want the widget to still be stylable using stylesheets. I understand that I should use QStylePainter in paintEvent, but I can't figure out which draw method to use (I must be stupid).
{
option.initFrom(this);
switch (this->m_someProperty) {
case 0:
color
= QColor::fromRgb(255,
255,
255);
break;
case 1:
color
= QColor::fromRgb(211,
211,
211);
break;
}
painter. //What to use here?
}
void MyWidget::paintEvent(QPaintEvent *)
{
QStylePainter painter(this);
QStyleOption option;
option.initFrom(this);
QColor color;
switch (this->m_someProperty) {
case 0:
color = QColor::fromRgb(255, 255, 255);
break;
case 1:
color = QColor::fromRgb(211, 211, 211);
break;
}
painter. //What to use here?
}
To copy to clipboard, switch view to plain text mode
Thanks.
Bookmarks