[Interest] Replacing QIcon with QImage in a existing model, how can i do that?

Mark markg85 at gmail.com
Sat Nov 24 22:43:54 CET 2012


Hi,

I'm working on a model structure where i have a file overview. Now
files can mean images as well and in the background there is a process
running that looks up the images and makes thumbnails from it.

So by default i show a QIcon because creating the thumbnail could take
a while on big folders and that would slow everything down in the
model if i where to add it directly. When the thumbnail is created it
should replace the current QIcon.

How i'm fetching the index is like this:
QModelIndex modelIndex = index(row, 0);

Yes, 0 for the column. And i'm guessing that's where i do things
wrong. The roles look as follows:
    QHash<int, QByteArray>roleNames;
    roleNames[Qt::DecorationRole] = "decoration";
    ...
    roleNames[Thumbnail]                = "Thumbnail";
    ....
    setRoleNames(roleNames);

Now i was expecting this to work:
setData(modelIndex, _my_qimage_thumbnail_, Thumbnail);

Sadly that doesn't work. setData will just return false. So what am i
doing wrong here? Is the index build up wrongly? Or do i need to do
some different role stuff?

Oddly, getting the data (The current QIcon) does work in the same fashion:
data(index, Thumbnail);

That works just fine so that leads me to think that the index is fine..

Any help would be very much appreciated.
Btw. this is Qt 4.8.3, not 5.0.

Cheers,
Mark



More information about the Interest mailing list