View Full Version : (Qt 4) QTreeview and Icons?

17th August 2006, 12:53

im using a QTreeView with a QAbstractItemModel.
Now i like to show a Icon for each Level, like QDirModel does.
level 1 shows icon1.png
level 2 shows icon2.png

How can i do that?

17th August 2006, 14:32

bool QAbstractItemModel::setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole )


bool QAbstractItemModel::setItemData ( const QModelIndex & index, const QMap<int, QVariant> & roles ) [virtual]

17th August 2006, 15:40
Thank you for the tip! i was just searching for icons, didnt thought of roles.
But how can i use it? Do you have an short example code?
Just the thing with showing icons, i dont need to change data in the model, mine is readonly.

17th August 2006, 15:46
Return the pixmap in

QVariant QAbstractItemModel::data(const QModelIndex& index, int role = Qt::DisplayRole) const
for role Qt::DecorationRole.

more or less like this:

QVariant MyModel::data(const QModelIndex& index, int role = Qt::DisplayRole) const
if (role == Qt::DecorationRole)
return QPixmap("some.png");

17th August 2006, 17:06
yippih.. thats is!! Thank you so much!!
You saved me many hours of searching, reading my book and trying!