Does QQuickImageProvider use QPixmapCache ?
-
I have 7 QML image elements in a QML page and the image sources are change (every image has 5 different optional sources).
I saw that every source change calls the PixmapImageProvider::requestPixmap to load the image again and I want to reduce the number of times images will be reloaded again. -
IIRC, changing the source explicitly evicts the image element from the cache, so you want to avoid that as much as possible. What you want is to create one Image element for each of the sources and alternate between which one is visible: true.
For instance:
@
// ImageFlipper.qml
Item {
id: root
property int index: 0;
Image { source: "source1.png"; visible: root.index == 0 }
Image { source: "source2.png"; visible: root.index == 1 }
Image { source: "source3.png"; visible: root.index == 2 }
Image { source: "source4.png"; visible: root.index == 3 }
Image { source: "source5.png"; visible: root.index == 4 }
}
@ -
I saw on qquickpixmapcache.cpp that if the QQuickImageProvider image type is QQuickImageProvider::Pixmap, the createPixmapDataSync function convert the pixmap to QImage.
Is it better to use QQuickImageProvider::Image as the image type of the QQuickImageProvider ? -
The default implementation of QPixmap is based on QImage, so the conversion cost between the two is negligible.
QPixmap has some code making sure the format is somewhat more optimal though, such as keeping the image in ARGB32_Premultiplied and maybe discarding the alpha channel of pngs which in practice have no alpha, so you are probably better off using Pixmap.