This is a little tricky but once you get the hang of it, it's pretty easy.
For any custom type that you want to use with a QVariant, you need to declare and register it so the metacompiler knows about it.
You declare your custom type with:
Q_DECLARE_METATYPE(QImage);
To copy to clipboard, switch view to plain text mode
The registering is done via:
qRegisterMetaType<QImage>();
qRegisterMetaType<QImage *>();
qRegisterMetaType<QImage>();
qRegisterMetaType<QImage *>();
To copy to clipboard, switch view to plain text mode
Registering is mandatory when using threads (queued connections)
http://doc.qt.nokia.com/4.6/custom-types.html
You can then use it in a QVariant like this:
QImage anotherImage
= myImageVariant.
value<QImage>
();
QImage myImage(...);
QVariant myImageVariant = QVariant(myImage);
QImage anotherImage = myImageVariant.value<QImage>();
To copy to clipboard, switch view to plain text mode
About the drawing:
Always draw only those things that are really on the screen. Things that are not on the screen waste computing power when they are drawn (unless of course you want to do some caching for example).
The models come with an option called fetchMore and canFetchMore.
Implement those to tell the view to only get the data from the model for the items on the screen, or the first 20 items etc...
Bookmarks