Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. grabWindow only grabs desktop background in macOS Catalina

grabWindow only grabs desktop background in macOS Catalina

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 555 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • freddy311082F Offline
    freddy311082F Offline
    freddy311082
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • freddy311082F freddy311082

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • freddy311082F Offline
        freddy311082F Offline
        freddy311082
        wrote on last edited by
        #3

        Awesome @jsulm... it works !!! Thank you very much !!!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved