View Full Version : (Qt 4) QTreeview and Icons?
pinktroll
17th August 2006, 11:53
Hello,
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?
munna
17th August 2006, 13:32
use
bool QAbstractItemModel::setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole )
or
bool QAbstractItemModel::setItemData ( const QModelIndex & index, const QMap<int, QVariant> & roles ) [virtual]
pinktroll
17th August 2006, 14: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.
jpn
17th August 2006, 14: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");
}
...
}
pinktroll
17th August 2006, 16:06
yippih.. thats is!! Thank you so much!!
You saved me many hours of searching, reading my book and trying!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.