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

    • Platform/s:
      Windows
    • Commits:
      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

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

          Activity

            People

            Assignee:
            qt.team.quick.subscriptions Qt Quick and Widgets Team
            Reporter:
            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