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

QWidnow::setGeometry coordinate system does not relate to QScreen::virtualGeometry

    XMLWordPrintable

Details

    • Windows

    Description

      The document of QWidnow::setGeometry said the coordinate system is realted to QScreen::virtualGeometry, however, it appears wrong if any screen has devive pixel ratio greater than 1.

      It seems QScreen::geometry and QScreen::virtualGeometry all return QRect in device independent pixel (that is, divided by devicePixelRatio), but QWindow::setGeometry expect QRect in pixels.

      If you try to set window to fullfill all screens (and screens have devicePixelRatio > 1)

      widnow->setGeometry(screen->virtualGeometry());
      

      You will notice it will not cover all screens, but if I do the calculation to convert virtualGeometry to pixel, it works fine.

      static QRectF patchedVirtualGeometry(QWidnow* widnow)
      {
          QRectF rect;
          for (auto sibling : window->screen()->virtualSiblings()) {
              auto box = sibling->geometry();
              box.setTopLeft(box.topLeft() * sibling->devicePixelRatio());
              box.setSize(box.size() * sibling->devicePixelRatio());
              rect |= box;
          }
          return rect;
      }
      
      // doc say so, but does not work
      window->setGeometry(widnow->screen()->virtualGeometry()); 
      
      // have to use this
      window->setGeometry(patchedVirtualGeometry(window)); 
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sorvig Morten Sørvig
            steve.k.chiu Steve K. Chiu
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes