Search code examples
qtscreenshot

How to get pixel under mouse cursor


Are there any ways to get pixel color under mouse cursor? (For not my windows).

I'm looking for cross-platform solutions. But it will be enought to provide mac os solution.


Solution

  • If you have id of window you can try this: http://qt-project.org/doc/qt-4.8/qpixmap.html#grabWindow

     QPixmap pixmap = QPixmap::grabWindow(QApplication::desktop()->winId(), x, y, 1, 1);
     QRgb pixelValue = pixmap.toImage().pixel(0,0);