[Interest] Re: Replacing QIcon with QImage in a existing model, how can i do that?
jkt at flaska.net
Mon Nov 26 17:10:22 CET 2012
On Saturday, 24 November 2012 22:43:54 CEST, Mark wrote:
> 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?
It is important to know what model implementation you're using. I'll assume you're subclassing a QAbstractItemModel. If you're using QStandardItemModel, you should call setItem() instead of setData(), according to the docs (because QSIM doesn't override setData() and QAIM's setData() doesn't do anything but return false).
Your model's data() function typically checks the role and returns appropriate data for the index the caller is requesting. In this case, all you have to do is to update the data structure which your data() reimplementation references, which will make sure that on a subsequent call, your data() will return the QImage you just computed instead of the default icon.
But that's not enough, because the views have no way to know that they should request the data once again, you shall have your model emit dataChanged() for the appropriate index at the time your process is finished with computing the thumbnail image.
With kind regards,
More information about the Interest