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

Custom cursors on X11 don't respect high DPI scaling

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.5.1
    • GUI: High-DPI
    • None
    • Linux/X11

    Description

      The example code below creates a 32-logical-pixels-tall window and sets a custom 2x-scaled cursor. The cursor size should match the window height exactly, and the hotspot should lay at the center of the cursor.

      #include <QWindow>
      #include <QGuiApplication>int main(int ac, char *av[])
      {
          QGuiApplication app(ac,av);
          QWindow w;
          QImage image(64, 64, QImage::Format_ARGB32);
          image.fill(0);
          auto pixels = (uint32_t*)image.bits();
          for(int i=0;i<64;i++) {
              pixels[i*64+i] = 0xffff0000;
              pixels[i*64+63-i] = 0xff0000ff;
          }
          auto pixmap = QPixmap::fromImage(image);
          pixmap.setDevicePixelRatio(2);
          w.setCursor(QCursor(pixmap, 16, 16));
          w.resize(200, 32);
          w.show();
          app.exec();
          return 0;
      }

      This works correctly on Windows and Mac. On X11 however, two issues are apparent:

      1. The pixmap's devicePixelRatio is ignored and the cursor is 64x64 even on low-dpi displays. This also causes the hotspot position to be applied incorrectly
      2. The display scaling factor is ignored and the cursor size doesn't match the window size on high-dpi displays (except for exact 2x scaling where the two issues cancel out).

      Attachments

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

        Activity

          People

            liaqi Liang Qi
            anszom Andrzej Szombierski
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes