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. QScreen returning the wrong size for my monitor
Forum Updated to NodeBB v4.3 + New Features

QScreen returning the wrong size for my monitor

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 2.8k 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.
  • F Offline
    F Offline
    feistykittykat
    wrote on last edited by
    #1

    Hi all,

    Currently I have two 4k monitors and a 1920x1080 tablet connected to my PC, running Windows 10 and Qt 5.15. I have the following loop:

        std::vector<QSize> resolutions;
        std::vector<float> dpis;
        for (const auto* screen : QGuiApplication::screens()) {
            resolutions.push_back(screen->size());
            dpis.push_back(screen->logicalDotsPerInch());
        }
    

    I would expect the values for my resolutions to be { QSize(3840 , 2160), QSize(3840 , 2160), QSize(1920, 1080)} . However, for some strange reason, all of my values are halved, and I get { QSize(1920, 1080), QSize(1920, 1080), QSize(960, 540)}. Is there something weird about the size() routine that I'm missing? The units should be pixels, so I'm really thinking this is a bug with Qt.

    I'll add that window sizes are also similarly incorrect when I try to query them. QGuiApplication::primaryScreen also errantly returns 1920x1080 as my screen dimensions, which should be 4k.

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      It sounds like high DPI scaling by a factor of 2.0.

      https://doc.qt.io/qt-5/highdpi.html
      https://doc.qt.io/qt-6/highdpi.html

      The Qt 5 version goes into more detail.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      F 1 Reply Last reply
      1
      • jeremy_kJ jeremy_k

        It sounds like high DPI scaling by a factor of 2.0.

        https://doc.qt.io/qt-5/highdpi.html
        https://doc.qt.io/qt-6/highdpi.html

        The Qt 5 version goes into more detail.

        F Offline
        F Offline
        feistykittykat
        wrote on last edited by feistykittykat
        #3

        @jeremy_k Thanks, that looks like a very possible explanation.

        Is there a way to check for the value of this factor at runtime? If not, I'm out of luck. Not sure if it matters, but I'm getting DPI values of 96 across the board for each screen.

        jeremy_kJ 1 Reply Last reply
        0
        • F feistykittykat

          @jeremy_k Thanks, that looks like a very possible explanation.

          Is there a way to check for the value of this factor at runtime? If not, I'm out of luck. Not sure if it matters, but I'm getting DPI values of 96 across the board for each screen.

          jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by
          #4

          Check the linked docs. There's been an evolution of how scaling is reported and controlled.
          For text, specifying in sizes in points instead of pixels should abstract the problem. If everything works as intended.

          96 dpi is or was a standard of sorts. Pulling from the Qt 5 high dpi documentation: The former is around twice the standard 96 DPI desktop resolution

          Asking a question about code? http://eel.is/iso-c++/testcase/

          F 1 Reply Last reply
          0
          • jeremy_kJ jeremy_k

            Check the linked docs. There's been an evolution of how scaling is reported and controlled.
            For text, specifying in sizes in points instead of pixels should abstract the problem. If everything works as intended.

            96 dpi is or was a standard of sorts. Pulling from the Qt 5 high dpi documentation: The former is around twice the standard 96 DPI desktop resolution

            F Offline
            F Offline
            feistykittykat
            wrote on last edited by
            #5

            @jeremy_k Thanks, I did give those docs a read, but they weren't particularly helpful. The solution was to use the devicePixelRatio() method of QScreen for appropriate scaling.

            M 1 Reply Last reply
            2
            • F feistykittykat

              @jeremy_k Thanks, I did give those docs a read, but they weren't particularly helpful. The solution was to use the devicePixelRatio() method of QScreen for appropriate scaling.

              M Offline
              M Offline
              Mr_Ada
              wrote on last edited by
              #6

              @feistykittykat Thank you very much! That worked for me as well. Was driving me nuts that it used to work when I was doing 5.x development and since going to 6.2.1 I have found a lot of gotchas in my code!

              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