Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.2.0
-
None
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
Issue Links
- clones
-
QTBUG-99472 "Pick Screen Color" button in QColorDialog doesn't scan secondary screen colors in Windows
- Closed
- relates to
-
QTBUG-129280 QScreen::grabWindow does not behave consistently across platforms
- Reported
-
QTBUG-100412 tst_qsrceen::grabWindow is flaky on Windows
- Closed