PDA

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



pinktroll
17th August 2006, 12: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, 14: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, 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.

jpn
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");
}
...
}

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