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

virtualGeometry size error caused by deviceIndependentGeometry error

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Invalid
    • Affects Version/s: 5.15.0
    • Fix Version/s: None
    • Component/s: GUI: High-DPI
    • Labels:
      None
    • Environment:
      UOS(Deepin)
    • Platform/s:
      Linux/X11

      Description

      When there are two screens, the calculation of virtualGeometry comes from screen->geometry(), while screen->geometry() comes from the function deviceIndependentGeometry(). This function does not calculate the zoom when calculating topleft (for example, the zoom ratio is 1.25). This leads to an increase in the calculation of virtualGeometry.

      or example: the first small screen is on the left, and the size is 1920*1080. The second large screen is on the right, and the size is 3840*2160. In the absence of scaling, the geometry of the two screens is (0,0,1920 + 0,1080 + 0) (1920,0,3840 1920 ,2160 + 0) Their virtualGeometry is (0,0,5760,2160) when the zoom factor is 1.25. Because topleft is not scaled in the deviceIndependentGeometry function, the scaled coordinates of the two screens are (0,0,1536 + 0,864 0) (1920,0,3072 1920,1728 0), and the calculated virtualGeometry (0 ,0,4992,1728).
      The virtualGeometry here is because topleft is not scaled, and the calculated size has exceeded the size of the screen. The correct size should be (0,0,4800(3072+1536),1728). So when zooming, we should consider geometry->topleft

       

      QRect QPlatformScreen::deviceIndependentGeometry() const
      {
          qreal scaleFactor = QHighDpiScaling::factor(this);
          QRect nativeGeometry = geometry();
          return QRect(nativeGeometry.topLeft(), QHighDpi::fromNative(nativeGeometry.size(), scaleFactor));
      }
      
      

      example:

      #include <QApplication>
      #include <QDebug>
      #include <QScreen>
      
      
      int main(int argc, char *argv[])
      {
      
          qputenv("QT_SCALE_FACTOR", "1.25");
      
          QApplication a(argc, argv);
          QWidget w;
      
          qDebug() << "MyMainWindow" <<qApp->screens().at(0)->geometry() << qApp->screens().at(1)->geometry() ;
          qDebug() << "MyMainWindow" <<qApp->screens().at(0)->virtualGeometry() << qApp->screens().at(1)->virtualGeometry() ;
          qDebug() << "MyMainWindow" <<qApp->screens().at(0)->availableGeometry() << qApp->screens().at(1)->availableGeometry() ;
      
      
          w.showFullScreen();
      
          return a.exec();
      }
      
      

        Attachments

        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:
            tanghaixiang haixiang tang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes