On Mon, Nov 26, 2012 at 5:10 PM, Jan Kundrát <j...@flaska.net> wrote:
> 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,
> Jan
> _______________________________________________
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

Hi Jan,

Thank you for your reply! I was using KDirModel [1] and that should
just work with setData since it has an implementation for that. It's
the Qt::DecorationRole. The thing i missed is some odd if statement
for the column "Name" requirement [2 line 797]. After i set my column
to that one it worked :)

I don't really get why it has that odd requirement..

[1] http://api.kde.org/4.9-api/kdelibs-apidocs/kio/html/classKDirModel.html
[2] 
http://api.kde.org/4.9-api/kdelibs-apidocs/kio/html/kdirmodel_8cpp_source.html
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to