It doesn't seem to be supported out of the box by the model-view framework. It only takes normal, selected and disabled modes of the icon into account. However, here's one way to work the limitation around:
Qt Code:
  1. #include <QtGui>
  2.  
  3. class ItemDelegate : public QStyledItemDelegate
  4. {
  5. public:
  6. ItemDelegate(QObject* parent = 0) : QStyledItemDelegate(parent)
  7. {
  8. }
  9.  
  10. void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
  11. {
  12. Q_ASSERT(index.isValid());
  13.  
  14. QStyleOptionViewItemV4 opt = option;
  15. initStyleOption(&opt, index);
  16.  
  17. if (opt.state & QStyle::State_MouseOver)
  18. opt.icon = opt.icon.pixmap(opt.decorationSize, QIcon::Active); // <--
  19.  
  20. QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 0);
  21. }
  22. };
  23.  
  24. int main(int argc, char* argv[])
  25. {
  26. QApplication app(argc, argv);
  27. list.setItemDelegate(new ItemDelegate(&list)); // <--
  28. list.viewport()->setAttribute(Qt::WA_Hover); // <--
  29.  
  30. QIcon icon;
  31. icon.addPixmap(QPixmap(":/trolltech/styles/commonstyle/images/standardbutton-no-16.png"), QIcon::Normal); // <--
  32. icon.addPixmap(QPixmap(":/trolltech/styles/commonstyle/images/standardbutton-yes-16.png"), QIcon::Active); // <--
  33.  
  34. for (int i = 0; i < 10; ++i)
  35. {
  36. item->setText(QString("item %1").arg(i));
  37. item->setIcon(icon); // <--
  38. list.addItem(item);
  39. }
  40. list.show();
  41. return app.exec();
  42. }
To copy to clipboard, switch view to plain text mode