High-DPI scaling in QQuickImageProvider
-
Hey there,
I'm encountering some problems working with high DPI scaling on my derived
QQuickImageProvider
.
Basically, I have two sets of images, one fordevicePixelRatio() == 1
, one fordevicePixelRatio() == 2
. The second set of images has twice the resolution of course.
My provider is given the right image path depending on the current screen'sdevicePixelRatio()
value.
On a device with a ratio of 1 everything is ok, however when the ratio is 2 my image has twice the expected size (which would mean dpi scaling is not working ?).
I've tried usingsetDevicePixelRatio()
but it does not seem to change anything.
High DPI scaling already works properly in usual cases (ex: QML image source contains "@2x").QPixmap ExternalImageQProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) { QPixmap empty; auto result = loadPixmap(id).value_or(empty); // Set DPI according to screen resolution (image source is given according to devicePixelRatio()) const auto dpr = QGuiApplication::primaryScreen()->devicePixelRatio(); result.setDevicePixelRatio(dpr); // this did not change anything. if (size) *size = result.size(); return result; }
-
I found a thread claiming this is a bug fixed in QT6: https://bugreports.qt.io/browse/QTBUG-96203
The provided fix. https://codereview.qt-project.org/c/qt/qtdeclarative/+/400147/2/src/quick/items/qquickimagebase.cppI'll just scale my picture in the meantime.