Unsolved Qt reporting higher device pixel ratio with windows scaling and AA_EnableHighDpiScaling for a standard machine
-
I am using a windows 10 machine. I am using Qt 5.12.11. This is the code I am using for a very simple app
int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true); QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } qreal MainWindow::detectDPR() { QWidget* topWindow= this->window(); float dpr; float dpi; float pdpi; topWindow->winId(); if (topWindow->windowHandle()) { dpr = topWindow->windowHandle()->devicePixelRatio(); dpi = (float)topWindow->windowHandle()->screen()->logicalDotsPerInch(); pdpi = (float)topWindow->windowHandle()->screen()->physicalDotsPerInch(); } qDebug() << dpi; qDebug() << dpr; qDebug() << pdpi; }
These are the results I observe.
When the flag enable high dpi is set
- Scale 100%
- DPI - 96
- DPR - 1
- PDPI - 96
- Scale 125%
- DPI - 120
- DPR - 1
- PDPI - 96
- Scale 150%
- DPI - 72
- DPR - 2
- PDPI - 48
When the flag is NOT set
- Scale 100%
- DPI - 96
- DPR - 1
- PDPI - 96
- Scale 125%
- DPI - 120
- DPR - 1
- PDPI - 96
- Scale 150%
- DPI - 144
- DPR - 1
- PDPI - 96
I am running this program on a standard display where physical dpi is 96. It is interesting that, just because the scale is 150%, Qt is bumping the DPR to 2 where my actual machine is a standard machine and NOT a high DPI machine. In such cases, our UI widgets are getting messed up.
My questions
- Shouldn't DPR be related to physical DPI?
- Why is the physical DPI being reduced by a factor of DPR?
Thanks
Chid - Scale 100%