grabWindow only grabs desktop background in macOS Catalina
-
Hi Guys
I'm working in an eyedropper component and I'm not able to take a good screenshot. The problem I have is with grabWindow which always takes the pixel value from the desktop wallpaper. It doesn't include any app in the screenshot.
The code I'm testing looks as this:
QMouseEvent* evMouse = dynamic_cast<QMouseEvent*>(ev); cout << "Posicion: " << evMouse->x() << ", " << evMouse->y() << endl; QPoint mousePos = QCursor::pos(); int screenNumber = qApp->desktop()->screenNumber(mousePos); QScreen* screen = qApp->screenAt(QCursor::pos()); cout << "Mouse Pos: " << mousePos.x() << ", " << mousePos.y() << ". Screen " << screenNumber << endl; QPixmap pixmap = screen->grabWindow(qApp->desktop()->winId(), mousePos.x(), mousePos.y(), 1, 1); Q_EMIT selectedPixelColor(pixmap.toImage().pixel(0, 0));
I'm running the project in macOS Catalina 10.15.5 against Qt 5.12.8.
Is there anything that I'm doing wrong here? Please, let me know if you need the entire code because it's test project and it's very small.
Regards
-
@freddy311082 said in grabWindow only grabs desktop background in macOS Catalina:
QPixmap pixmap = screen->grabWindow(qApp->desktop()->winId(), mousePos.x(), mousePos.y(), 1, 1);
I think you need to map the mouse coordinates to global: https://doc.qt.io/qt-5/qwidget.html#mapToGlobal
-
Awesome @jsulm... it works !!! Thank you very much !!!