How to change cursor to Qt.ForbiddenCursor while drag hover over a qlistwidget?
-
How to change the cursor icon to ForbiddenCursor while user drag item and hover mouse over a qlistwidget?
I have tried:def dragEnterEvent(self, event): if event.mimeData().hasFormat('text/plain'): self.setCursor(qt.Qt.ForbiddenCursor) event.ignore() else: event.accept() qt.QListWidget.dragEnterEvent(self, event)
but above code won't work while holding mouse left button down, setCursor works only after I release mouse left button.
Thanks in advance.
-
Hi,
You have to implement the drag enter and move events method and there not accept the proposed action.
-
@SGaist Thanks, could you give a code example here?
I have tried following:def mouseMoveEvent(self, event): if event.mimeData().hasFormat('text/plain'): event.ignore()
But the event in mouseMoveEvent does not have mimeData member method.
-
@Leon-Zhang
QDragMoveEvent
, notQMouseMoveEvent
. -
Not the mouse event handlers, the drag related event handlers.
-
@Leon-Zhang
That does not sound right, you having an override should not be relevant. Unless, at a guess, your override fails to call the base implementation, and that prevents the drag move event ever getting raised...? -
@Leon-Zhang
I don't know what you're up to, but so far as I recall and as @SGaist said you will need to override bothdragEnterEvent
anddragMoveEvent
to alter the cursor during a drag successfully.