Important: Please read the Qt Code of Conduct -

Capture Cursor

  • 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

  • Lifetime Qt Champion


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

  • Moderators

    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);
        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);
        ReleaseDC(NULL, hdc);
        return pixmap;

  • Thanks Chris I will give that a try.

Log in to reply