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 geometry & availableGeometry returns weird values
Forum Updated to NodeBB v4.3 + New Features

QScreen geometry & availableGeometry returns weird values

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 981 Views
  • 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.
  • J Offline
    J Offline
    JonathanA
    wrote on last edited by JonathanA
    #1

    I have 2 4k monitors set to scale at 150% on Windows 10 and I don't think the numbers are working out right for me. Here's my code:

            int screen_idx = 1;
            QList<QScreen*> screens(QGuiApplication::screens());
            Q_FOREACH( auto screen, screens)
            {
                const QRect screen_rect(screen->availableGeometry());
                const QRect pixel_rect(screen->geometry());
        
                qDebug() << "Screen #" << screen_idx << ": screen_rect: " << screen_rect << ", pixel_rect= " << pixel_rect;
                ++screen_idx;
            }
    

    and here is the output:

    Screen # 1 : screen_rect:  QRect(0,0 2560x1400) , pixel_rect=  QRect(0,0 2560x1440)
    Screen # 2 : screen_rect:  QRect(3840,0 2560x1400) , pixel_rect=  QRect(3840,0 2560x1440)
    

    Now one or both of those QRect for the sizes should be 3840x2160. The docs for geometry() in specific say:

    This property holds the screen's geometry in pixels
    

    Those are not pixels. Those are scaled pixels (2560x1.5=3840, 1440x1.5=2160). How do I get the actual number of pixels on each display?

    1 Reply Last reply
    0
    • hskoglundH Online
      hskoglundH Online
      hskoglund
      wrote on last edited by
      #2

      Hi, I think it depends on what DPI awareness you code (or rather your .exe file) is set to. Here's a quick way to test, create a text file called qt.conf with this contents:

      [Platforms]
      WindowsArguments = dpiawareness=1
      

      and place that file in the same directory as your .exe file. Restart your app, does this change the output?

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JonathanA
        wrote on last edited by
        #3

        Yes, I did realize I forgot one other piece of info. I do set a couple things:

        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
        

        But still - I just want the desktop size in pixels, so I can place my windows correctly.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JonathanA
          wrote on last edited by
          #4

          I've opened a Qt bug to track this: https://bugreports.qt.io/browse/QTBUG-84206

          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