Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt reporting higher device pixel ratio with windows scaling and AA_EnableHighDpiScaling for a standard machine
Qt 6.11 is out! See what's new in the release blog

Qt reporting higher device pixel ratio with windows scaling and AA_EnableHighDpiScaling for a standard machine

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 619 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chidambaram
    wrote on last edited by Chidambaram
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved