Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-84206

QScreen size() returns incorrect offset for second monitor

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.14.0 RC2
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      Windows 10 with 2 4k monitors, scaling set to 150%
    • Platform/s:
      Windows

      Description

      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:

      #include "mainwindow.h"
      
      #include <QApplication>
      #include <QScreen>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
      
          // Specific application options for high dpi screens
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      
      #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
          QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
      #endif
      
          QApplication a(argc, argv);
      
          int screen_idx = 1;
      
          QList<QScreen*> screens(QGuiApplication::screens());
          Q_FOREACH( auto screen, screens)
          {
              const QRect screen_rect(screen->availableGeometry());
              const QSize pixel_rect(screen->size());
      
              qDebug() << "Screen #" << screen_idx << ": screen_rect: " << screen_rect << ", pixel_rect= " << pixel_rect;
              ++screen_idx;
          }
      
          MainWindow w;
          w.show();
          return a.exec();
      }
      
      

      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?

        Attachments

        1. Qt Creator.lnk
          0.7 kB
        2. testscreens.zip
          5 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            sorvig Morten Sørvig
            Reporter:
            jdarnold Jonathan Arnold
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes