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. Capture Cursor
Qt 6.11 is out! See what's new in the release blog

Capture Cursor

Scheduled Pinned Locked Moved General and Desktop
windows
4 Posts 3 Posters 1.8k Views 3 Watching
  • 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.
  • RichardR Offline
    RichardR Offline
    Richard
    wrote on last edited by
    #1

    Hi All,
    I would like to use a custom QCursor with a Pixmap, but instead of create an entirely new shape I would rather capture the currently used arrow cursor and modify it a bit on the fly. So for this I would need to "Capture/screenshot" the current cursor shape into a Pixmap. Is this possible by any chance?

    thanks you
    rich.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      AFAICT it should be possible when using a QPixmap based cursor but it doesn't look like it for the default shapes

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        There doesn't seem to be a way to do that in Qt api (apart from the pixmap cursors as @SGaist mentioned), but if you're willing to go platform specific you can do that on windows with the help of some winapi and QtWinExtras module:

        #include <QPixmap>
        #include <QtWin>
        #include <Windows.h>
        
        QPixmap GrabCursor()
        {
            CURSORINFO info;
            info.cbSize = sizeof(info);
            GetCursorInfo(&info);
        
            int width = GetSystemMetrics(SM_CXCURSOR);
            int height = GetSystemMetrics(SM_CYCURSOR);
        
            HDC hdc = GetDC(NULL);
            HBITMAP bitmap = CreateCompatibleBitmap(hdc, width, height);
        
            HDC bitmapDC = CreateCompatibleDC(hdc);
            HGDIOBJ prevObj = SelectObject(bitmapDC, bitmap);
            DrawIcon(bitmapDC, 0, 0, info.hCursor);
        
            QPixmap pixmap = QtWin::fromHBITMAP(bitmap, QtWin::HBitmapAlpha);
        
            SelectObject(bitmapDC, prevObj);
            DeleteObject(bitmap);
            DeleteDC(bitmapDC);
            ReleaseDC(NULL, hdc);
        
            return pixmap;
        }
        
        1 Reply Last reply
        2
        • RichardR Offline
          RichardR Offline
          Richard
          wrote on last edited by
          #4

          Thanks Chris I will give that a try.

          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