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

QScreen::devicePixelRatio returns incorrect values(integer value) on Wayland with fractional scaling in both Qt5 and Qt6 (Manjaro).

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • None
    • 5.15.16, 6.9.0
    • GUI: High-DPI, QPA: Wayland
    • None
    • - Qt Version: [5.15.16]
      - OS: Manjaro Linux, Wayland and other distros supporting wayland
    • Linux/Wayland

    Description

      What did you do?

      I want to get devicePixelRatio with QScreen in Wayland of Manjaro. However, it always returns an integer value, even though I am running using a fractional scaling ratio.

      This is my display setup

      This is my Qt code

      I use code below to query the devicePiexlRatio using Qt5.

       

      #include <QApplication>
      
      #include <QScreen>
      
      #include <QDebug>
      
      
      
      int main(int argc, char *argv[]) {
      
          QApplication app(argc, argv);
      
      
      
          // Get the primary screen
      
          QScreen *screen = QApplication::primaryScreen();
      
          if (!screen) {
      
              qDebug() << "Error: No primary screen detected.";
      
              return 1;
      
          }
      
      
      
          // Query and print devicePixelRatio
      
          qreal pixelRatio = screen->devicePixelRatio();
      
          qDebug() << "Device Pixel Ratio:" << pixelRatio;
      
          qDebug() << "Screen Name:" << screen->name();
      
          qDebug() << "Physical DPI:" << screen->physicalDotsPerInch();
      
          qDebug() << "Logical DPI:" << screen->logicalDotsPerInch();
      
      
      
          return app.exec();
      
      } 

      I tested it with high dpi env var enabled or disabled, neither worked.

       

      The result is

       

      $./test_pixelratio
      
      Device Pixel Ratio: 2
      
      Screen Name: "eDP-1"
      
      Physical DPI: 126.192
      
      Logical DPI: 96
      
      
       

       

       

      What did you expect to happen?

      An accurate devicePixelRatio, in my case, should be 1.25.

      What happened instead?

      An integer value. It returns 2.

       

      What I am suspecting

      You didn't support fractional scaling ratio in QtWaylandScreen. I read the code, though it is qt6.

      It had implemented fractional_scale_v1, the wayland protocol that supports the fractional scaling ratio. And it had a fractional scaling manager. But it is only integrated into the qt wayland related window class, not QtWaylandScreen.

      I might also miss some other widgets or components that still fully supports fractional scaling ratio.

      Attachments

        For Gerrit Dashboard: QTBUG-135612
        # Subject Branch Project Status CR V

        Activity

          People

            sorvig Morten Sørvig
            tom_tony tom_tony
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There is 1 open Gerrit change