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

"Pick Screen Color" button in QColorDialog doesn't scan secondary screen colors in Windows

    XMLWordPrintable

Details

    • Windows
    • da6c8b2fc6 (qt/qtbase/dev) da6c8b2fc6 (qt/tqtc-qtbase/dev) 90e5e565f0 (qt/qtbase/6.3) 90e5e565f0 (qt/tqtc-qtbase/6.3) 22f682d620 (qt/qtbase/6.2) 22f682d620 (qt/tqtc-qtbase/6.2)

    Description

      The "Pick Screen Color" button in QColorDialog permits scanning the colors of the entire screen to pick one of them. But it's not possible to scan colors from a secondary screen (dual-screen, multi-screen...).

      The error probably lies in this method:

      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);
      }
      

      Suggested fix:

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

       
      Also, note that the cursor flickers when it moves on the secondary screen. No fix suggestion for that part. Might be somehow related to https://bugreports.qt.io/browse/QTBUG-43448

      Attachments

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              kimo Guillaume Breda
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes