PDA

View Full Version : Draw background of custom widget



lumiss
24th August 2010, 10:33
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).


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?
}


Thanks.