I know this has been asked many times but it hasn't been fully answered. I have also googled for quite some time now but haven't found anything helpfull yet.

So basically from the documentation I understand I need an Item Delegate to personalize the preview icon. Thats ok. So I did this test:

Qt Code:
  1. class PixmapPreviewDelegate : public QStyledItemDelegate
  2. {
  3. public:
  4. PixmapPreviewDelegate(QObject *parent = 0) :
  5. QStyledItemDelegate(parent)
  6. {
  7. }
  8.  
  9. void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const {
  10. painter->drawText(
  11. option.rect,
  12. displayText(index.data(), QLocale::system()),
  13. option.displayAlignment
  14. );
  15.  
  16. QStyleOptionViewItem auxOpcion = option;
  17. auxOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
  18. auxOption.rect.setWidth(auxOption.rect.height());
  19. painter->drawPixmap(auxOption.rect, QPixmap(":images/test.png"));
  20. }
  21. };
To copy to clipboard, switch view to plain text mode 

That worked ok. But I found I had lost all default styles (files where not highlighted when selected), which was unacceptable. Secondly, since the index data has only the file name I couldn't use it in the Pixmap constructor. So I need to constantly tell the delegate the current folder the user is seeing? Isn't this just crazy?

Then I thought I could just change the data's Qt:: DecorationRole in order to change the icon, but didn't know how to do this?
This doesn't seem to work:
Qt Code:
  1. void setModelData(QWidget * widget, QAbstractItemModel* item, const ModelIndex& index ) const {
  2. Q_UNUSED(widget);
  3. qDebug() << "setModelData";
  4. item->setData(index, QIcon(":images/test.png"), Qt::DecorationRole);
  5. }
To copy to clipboard, switch view to plain text mode 


I'm really stuck with this.

Thanks for any help.