Load image in background thread in QStyledItemDelegate
-
Is this possible? I know in QML you can load images (from HTTP) in the background but is it also possible with Qt Widgets? I guess one would have to re-trigger a paint of the item once the background thread finished?
-
Hi,
Your question is a bit misleading, do you want to load an image from a thread and show it on a widget ? Or have it in a model and then shown through a delegate ?
-
I have a model and want to show it through a delegate.
-
Then your background thread should load the the data, create a QImage and update the content of your model with that image. You can also save the loaded data directly in your model (if they are e.g. jpeg images) and create the image in your delegate.
You should test the two versions for performance.
-
Once I set the image in my model, how does the model notify the view about this change and the view re-renders the item?
-
Since it's a custom model it's up to you to do that. Have a look at e.g. "QAbstractItemModel"http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html documentation. It explains how to do it