Hi! I would like to create a button whose icon is changed according to its state, i.e. an icon is set if it is not focused and another when it has the focus. I wrote this in the drawControl method of a style I wrote:

Qt Code:
  1. switch (element) {
  2. case QStyle::CE_PushButtonBevel: {
  3. // I have to draw the label.
  4. const QStyleOptionButton *buttonOpt = qstyleoption_cast<const QStyleOptionButton *>(option);
  5. QPushButton* buttonWidget = (QPushButton*)widget;
  6.  
  7. // Draw the correct icon.
  8. qDebug(QString::number(buttonOpt->state, 16).toStdString().c_str());
  9. if ((buttonOpt->state & QStyle::State_HasFocus) == QStyle::State_HasFocus)
  10. // Draw the default pixmap.
  11. painter->drawPixmap(buttonOpt->rect, buttonOpt->icon.pixmap(buttonWidget->size(), QIcon::Selected));
  12. else
  13. // Draw the pixmap to be used in case the widget is focused.
  14. painter->drawPixmap(buttonOpt->rect, buttonOpt->icon.pixmap(buttonWidget->size(), QIcon::Normal));
  15. break;
  16. }
  17. default:
  18. QWindowsStyle::drawControl(element, option, painter, widget);
  19. break;
  20. }
To copy to clipboard, switch view to plain text mode 

It seems it doesn't work and I'm quite far. I get two icons inside the button. Any idea how I can achieve what I need?
Thanks!