edA-qa mort-ora-y
edA-qa mort-ora-y

Reputation: 31951

Qt set custom drag cursor?

How can I set the cursor used in Qt while performing a drag operation? I am using the QDrag class. The function setCursor takes a pixmap and has no way to specify the hotspot, nor do the docs specify that it could override the "no action" cursor.

I'm happy if I can just do an explicit cursor in mouseMoveEvent but I'm not sure how during a drag operation.

Upvotes: 4

Views: 4731

Answers (1)

edA-qa mort-ora-y
edA-qa mort-ora-y

Reputation: 31951

Checking the source code it appears Qt is lame in this regards and has no mechanism to do this. For the X11 code the function QDragManager::updateCursor variables which contain the cursors it uses. Those are created using the QCursor constructor with constant hot-spot values (0,0). The ForbiddenCursor is completely hard-coded, thus preventing any alternation.

To set the cursor it calls QApplication::changeOverrideCursor. As a static function there is no way to intercept that call.


Even if the pixmaps are set (via setCursor) the intial drag cursor is still the default. This just appears to be a defect in QT. This is at qdnd_x11.cpp:1948, the pointer cursor is forcibly set at the start of a drag

Thus there is no actual way to use custom cursors for the standard drag-n-drop.

Upvotes: 4

Related Questions