High DPI scaling of QQuickItem derived object
-
Hello,
I use QtQuickControls 2 together with QQuickItem-derived class in my app. After I set AA_EnableHighDpiScaling attribute and all QQuickControls 2 components look correctly on my smartphone but object of my custom class is scaled incorrectly. Here is the app without HighDpi scaling with minimum zoom(the way it is meant to work):
http://pasteboard.co/6dmRQpVaZ.png
And here is the one with scaling with minimum zoom:
http://pasteboard.co/CxdoQ7rr.png
It seems that on the second screen the object is scaled too much and I can see square pixels of all textures that I draw with QPixmap or QImage. However, the images that I load from external memory and nodes like QSGGeometryNode look correct. Could someone tell me what is the problem? Can I switch off scaling for just one particular QQuickItem? If no, what should I set to render it correctly?
Also, when I try to set opacity on QQuickItem with a lot of QSGOpacityNodes in scene graph node tree I get segmentation fault. What can cause this?
Regards, Artem
-
Hello,
I use QtQuickControls 2 together with QQuickItem-derived class in my app. After I set AA_EnableHighDpiScaling attribute and all QQuickControls 2 components look correctly on my smartphone but object of my custom class is scaled incorrectly. Here is the app without HighDpi scaling with minimum zoom(the way it is meant to work):
http://pasteboard.co/6dmRQpVaZ.png
And here is the one with scaling with minimum zoom:
http://pasteboard.co/CxdoQ7rr.png
It seems that on the second screen the object is scaled too much and I can see square pixels of all textures that I draw with QPixmap or QImage. However, the images that I load from external memory and nodes like QSGGeometryNode look correct. Could someone tell me what is the problem? Can I switch off scaling for just one particular QQuickItem? If no, what should I set to render it correctly?
Also, when I try to set opacity on QQuickItem with a lot of QSGOpacityNodes in scene graph node tree I get segmentation fault. What can cause this?
Regards, Artem
-
@raven-worx Thank you for your reply. I solved the problem by dividing QSGTexture's size by the QQuickWindow::effectiveDevicePixelRatio()
I have another problem now. I use prescaled bitmap images for different dpi. However, when I set AA_EnableHighDpiScaling attribute images in QML are scaled more than I need. I tried to use @2x prefix but it doesn't work on Android (it is Apple specific). Is there a better solution than always dividing the size of image by pixel ratio?
Personally I'm upset with the way high dpi scaling works. Qt documentation suggests to use prescaled images for each dpi but why there is no way to tell that Image is already scaled?
-
@raven-worx Thank you for your reply. I solved the problem by dividing QSGTexture's size by the QQuickWindow::effectiveDevicePixelRatio()
I have another problem now. I use prescaled bitmap images for different dpi. However, when I set AA_EnableHighDpiScaling attribute images in QML are scaled more than I need. I tried to use @2x prefix but it doesn't work on Android (it is Apple specific). Is there a better solution than always dividing the size of image by pixel ratio?
Personally I'm upset with the way high dpi scaling works. Qt documentation suggests to use prescaled images for each dpi but why there is no way to tell that Image is already scaled?
@polaris said:
I have another problem now. I use prescaled bitmap images for different dpi. However, when I set AA_EnableHighDpiScaling attribute images in QML are scaled more than I need. I tried to use @2x prefix but it doesn't work on Android (it is Apple specific). Is there a better solution than always dividing the size of image by pixel ratio?
Using the Screen type. Also you may want to read this
Image { source: { if (Screen.PixelDensity < 40) "image_low_dpi.png" else if (Screen.PixelDensity > 300) "image_high_dpi.png" else "image.png" } }
alternatively you can implement such smart behavior hidden within a custom QQuickImageProvider
-
@polaris said:
I have another problem now. I use prescaled bitmap images for different dpi. However, when I set AA_EnableHighDpiScaling attribute images in QML are scaled more than I need. I tried to use @2x prefix but it doesn't work on Android (it is Apple specific). Is there a better solution than always dividing the size of image by pixel ratio?
Using the Screen type. Also you may want to read this
Image { source: { if (Screen.PixelDensity < 40) "image_low_dpi.png" else if (Screen.PixelDensity > 300) "image_high_dpi.png" else "image.png" } }
alternatively you can implement such smart behavior hidden within a custom QQuickImageProvider
@raven-worx I'm doing exactly the same thing as in your code. However, Qt scales all types of images regardless of their resolution when I switch on high dpi scaling. To cancel this scaling I have to divide width and height of Image by Screen.pixelRatio. I wonder, how can I specify that this Image is already scaled to specific dpi and disable standard high dpi scaling for this Image?
In Qt Quick Controls 2.0 Gallery example @2x like suffixes are used for higher dpi versions of images. Does this technique work on Android? -
@raven-worx I'm doing exactly the same thing as in your code. However, Qt scales all types of images regardless of their resolution when I switch on high dpi scaling. To cancel this scaling I have to divide width and height of Image by Screen.pixelRatio. I wonder, how can I specify that this Image is already scaled to specific dpi and disable standard high dpi scaling for this Image?
In Qt Quick Controls 2.0 Gallery example @2x like suffixes are used for higher dpi versions of images. Does this technique work on Android?@polaris said:
In Qt Quick Controls 2.0 Gallery example @2x like suffixes are used for higher dpi versions of images. Does this technique work on Android?
Yes, Qt has fully cross-platform high DPI support since version 5.6. Notice that if you are reading images from disk with QPixmap or QImage, they do not select @Nx high DPI versions. You can use QIcon (or at your own risk, undocumented qt_findAtNxFile() declared in qicon.h) to load high DPI versions.