Android QT quick control 2 zoom
I'm developing applications that should run on mobile and desktop platforms. I find that the size of controls varies on different screens: in high-density screens, the controls are too small and in low-density screens, they are large
I can calculate the scale factor of each screen (i.e. the density independent pixels of Android) and use it to define the item size, margin, etc. in DP:
ApplicationWindow {
...
property real dp: Screen.pixelDensity * 10 * 2.54 / 160
Item {
width: 50*dp
height: 50*dp
...
Label {
font.pixelSize: 16*dp
...
}
}
}
It works well, but it seems that the size of standard controls in QT quick controls 2 is defined in pixels, so they cannot be scaled. The only way I see is to redefine all controls in QT quick controls 2 with DP instead of pixels
Therefore, I am looking for a way to extend standard controls without redefining all standard controls
UPD1. I have tried "high DPI support", which can make the situation better, but there are still some problems. The following are some parameters from the home screen (see paramter description here) of different devices before and after applying high DPI support:
// samsung tab t-280 without high dpi support
devicePixelRatio 1
geometry QRect(0,0 800x1280)
logicalDotsPerInch 95.85
physicalDotsPerInch 216.458
physicalSize QSizeF(94, 150) (7')
// samsung tab t-280 with high dpi support
devicePixelRatio 1.33125
geometry QRect(0,0 601x962)
logicalDotsPerInch 72
physicalDotsPerInch 162.648
physicalSize QSizeF(94, 150) (7')
// xiaomi redmi 2 without high dpi support
devicePixelRatio 1
geometry QRect(0,0 720x1280)
logicalDotsPerInch 144
physicalDotsPerInch 315.48
physicalSize QSizeF(58, 103) (4.6')
// xiaomi redmi 2 with high dpi support
devicePixelRatio 2
geometry QRect(0,0 360x640)
logicalDotsPerInch 72
physicalDotsPerInch 157.74
physicalSize QSizeF(58, 103) (4.6')
// macbook pro retina 13' without high dpi support
devicePixelRatio 2
geometry QRect(0,0 1280x800)
logicalDotsPerInch 72
physicalDotsPerInch 113.5
physicalSize QSizeF(286.449, 179.031) (13')
// macbook pro retina 13' with high dpi support
devicePixelRatio 2
geometry QRect(0,0 1280x800)
logicalDotsPerInch 72
physicalDotsPerInch 113.5
physicalSize QSizeF(286.449, 179.031) (13')
// generic 20' display without high dpi support
devicePixelRatio 1
geometry QRect(0,0 1280x1024)
logicalDotsPerInch 72
physicalDotsPerInch 72
physicalSize QSizeF(451.556, 361.244) (22.6')
// generic 20' display with high dpi support
devicePixelRatio 1
geometry QRect(0,0 1280x1024)
logicalDotsPerInch 72
physicalDotsPerInch 72
physicalSize QSizeF(451.556, 361.244) (22.6')
// asus zenbook 13' without high dpi support
devicePixelRatio 1
geometry QRect(0,0 1366x768)
logicalDotsPerInch 96
physicalDotsPerInch 71.9833
physicalSize QSizeF(482, 271) (21.6'!)
// asus zenbook 13' with high dpi support
devicePixelRatio 1
geometry QRect(0,0 1366x768)
logicalDotsPerInch 96
physicalDotsPerInch 71.9833
physicalSize QSizeF(482, 271) (21.6'!)
For some high DPI displays (Samsung tablets and Xiaomi phones), the situation seems to be better. After applying for high DPI support, the DPI of both devices is close to 160
However, the DPI of retina display and low-density display will not change, and the items on the screen look larger than they should. Therefore, it can only solve half of the original problem. Maybe someone knows how to manually set the scale factor for all QT applications at run time?
resolvent:
I encountered the same problem and found that jpnurmi's answer was the most helpful: add
qputenv("QT_SCALE_FACTOR", "3");
Before creating the application instance, in main (). For my retina display, the coefficient of 0.75 works well for me because these displays are actually too large