Important: Please read the Qt Code of Conduct -

PickerColor in multiple displays context

  • bug_picker_color.png


    If you look at my screen configuration, I actually get the color, when I'm in the first blue area, of the second blue area. Kind of like if there's an overlap of the two screens... I use the QScreen::grabWindow method but I try hard to change the offsets, but it has no influence on the result...
    The black area means that when I walk with my mouse in this area, I get the color black... which is logical because for him, I'm outside the screen... but why...
    And for the screen on the far right, which is my secondary screen (in 1920), it works very well.
    For the coordinates that I get from the mouse, it is coordinates that consider the merging of the two screens.

    For those who want to test the behavior and have two screens, you can quickly make a MyWidget class derived from QWidget and override the mouseMoveEvent method for example like this :

    MyWidget::mouseMoveEvent( QMouseEvent* event )
        QPoint mousePosition = event->globalPos();
        QList< QScreen* > screens = QGuiApplication::screens();
        QColor color;
        for ( int i = 0; i < screens.count(); ++i )
            if ( screens[i]->geometry().contains( mousePosition.x(), mousePosition.y() ) )
                QPixmap pixmap = screens[i]->grabWindow( 0, mousePosition.x(), mousePosition.y(), 1, 1 );
                QImage image( pixmap.toImage() );
                color = image.pixelColor( 0, 0 );
        QPalette palette( color );
        setPalette( palette );
        QWidget::mouseMoveEvent( event );

    If you have an idea on how to correctly retrieve the color under the mouse in a multi-screen context, I'm interested :)

Log in to reply