Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: Get a standard cursor pixmap

The QCursor class provides methods get and set a QPixmap or a QBitmap on the cursor. I can create a cursor from one of the standard shapes, e.g. Qt::ArrowCursor. However, if I do so, I cannot get the pixmap/bitmap of the cursor!

QCursor cursor(Qt::ArrowCursor);
qDebug() << cursor.pixmap().isNull()
         << cursor.bitmap()
         << cursor.mask();

Will generate the output

true 0x00 0x00

I know the documentation says it's not possible, but I need to get the pixmap/icon/image/animation/whatever of a specific cursor.

So, is there a way to get the icon of a standard cursor from Qt? I'm wondering because if you drag an item from a QListView, it will show both, the standard cursor an the image of whatever I am dragging!

like image 774
Felix Avatar asked Sep 18 '25 08:09

Felix


1 Answers

Plain and simple, you can't.

QPixmap QCursor::pixmap() const

Returns the cursor pixmap. This is only valid if the cursor is a pixmap cursor.

The reason is that for builtin cursors Qt just asks the operating system to use that particular shape by means of symbolic constants, without ever accessing the actual pixmap.

like image 127
peppe Avatar answered Sep 19 '25 22:09

peppe