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).

Qt Code:
  1. void MyWidget::paintEvent(QPaintEvent *)
  2. {
  3. QStylePainter painter(this);
  4.  
  5. QStyleOption option;
  6. option.initFrom(this);
  7.  
  8. QColor color;
  9. switch (this->m_someProperty) {
  10. case 0:
  11. color = QColor::fromRgb(255, 255, 255);
  12. break;
  13. case 1:
  14. color = QColor::fromRgb(211, 211, 211);
  15. break;
  16. }
  17.  
  18. painter. //What to use here?
  19. }
To copy to clipboard, switch view to plain text mode 

Thanks.