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

QScreen::grabWindow(0, ...) isn't working on second display

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 6.2.0
    • Fix Version/s: None
    • Component/s: QPA: Windows, QPA: X11/XCB
    • Labels:
      None
    • Platform/s:
      Linux/X11, Windows

      Description

      When trying to use QScreen::grabWindow(0, ...) in a multi display setup on the second screen it returns random color values (see attached videos).
      I've tested this by using the QColorDialog "Pick Screen Color" functionality compiled with Qt 6.2.0

      #include <QApplication>
      #include <QDebug>
      #include <QColorDialog>
      
      class QColorDialogTester : public QWidget
      {
      public:
          void onColor()
          {
              QColor color = QColorDialog::getColor(Qt::yellow,
                                                    this,
                                                    "Color Dialog",
                                                    QColorDialog::DontUseNativeDialog);
      
              if (color.isValid())
                  qDebug() << "Choosen color: " << color.name();
          }
      
      };
      
      int main(int argc, char **argv)
      {
          QApplication app(argc, argv);
          QColorDialogTester color_test;
          color_test.onColor();
          return 0;
      }
      

      I've tested it with Ubuntu 20.04, xfce 4.14, X11, two displays and Windows 10 (DELL U3818DW which is internally also two displays).

      Prior to Qt 6 the QColorDialogPrivate::grabScreenColor looked as follows:

      QColor QColorDialogPrivate::grabScreenColor(const QPoint &p)
      {
          const QDesktopWidget *desktop = QApplication::desktop();
          const QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(desktop->winId(), p.x(), p.y(), 1, 1);
          QImage i = pixmap.toImage();
          return i.pixel(0, 0);
      }
      

      This was working fine on all displays (not only the primary one). In Qt 6 the QDesktopWidget isn't available anymore this is why the ported function looks like this:

      QColor QColorDialogPrivate::grabScreenColor(const QPoint &p)
      {
          QScreen *screen = QGuiApplication::screenAt(p);
          if (!screen)
              screen = QGuiApplication::primaryScreen();
          const QPixmap pixmap = screen->grabWindow(0, p.x(), p.y(), 1, 1);
          const QImage i = pixmap.toImage();
          return i.pixel(0, 0);
      }
      

      But this only works on the primary display as shown in the two attached videos.

        Attachments

        1. primary-display.mp4
          1.04 MB
        2. second-display.mp4
          1.31 MB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            vhilshei Volker Hilsheimer
            Reporter:
            henning Henning Gründl
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes