Restored cursor stays as ForbiddenCursor one after drag and drop
-
I have a python application that provides drag and drop functionality - items from a tree (implemented as a QTreeWidget) can be dropped to the canvas (implemented as QGraphicsView). Now, some of those objects need to be initialized when dropped and to avoid that delay, there is a separate thread created that takes care of this.
Cursor is changed to the WaitCursor right before thread is created/started, by using setOverrideCursor method.
QApplication.setOverrideCursor(Qt.WaitCursor)I have a signal that is sent when thread is finished to restore cursor back with restoreOverrideCursor.
QApplication.restoreOverrideCursor()But, during the process of dragging, something else changes cursor as well and when all is done, cursor stays as ForbiddenCursor instead of Arrow that is needed.
If I just bring mouse pointer outside of the canvas area, that by itself resets the cursor back to the Arrow one.
The question here is what else can I do in my code to get that cursor to get restored back to the Arrow one?
-
I have a python application that provides drag and drop functionality - items from a tree (implemented as a QTreeWidget) can be dropped to the canvas (implemented as QGraphicsView). Now, some of those objects need to be initialized when dropped and to avoid that delay, there is a separate thread created that takes care of this.
Cursor is changed to the WaitCursor right before thread is created/started, by using setOverrideCursor method.
QApplication.setOverrideCursor(Qt.WaitCursor)I have a signal that is sent when thread is finished to restore cursor back with restoreOverrideCursor.
QApplication.restoreOverrideCursor()But, during the process of dragging, something else changes cursor as well and when all is done, cursor stays as ForbiddenCursor instead of Arrow that is needed.
If I just bring mouse pointer outside of the canvas area, that by itself resets the cursor back to the Arrow one.
The question here is what else can I do in my code to get that cursor to get restored back to the Arrow one?
One more test that still didn't work.
Once I get a signal that thread has finished, in the slot code I have added join() call to make sure thread has really finished, so the cursor is not prematurely changed, but that didn't help and I still ended up with ForbidenCursor.
class MyClass(): threadDone = Signal() def __init__(self): self.threadDone.connect(self.onThreadDone) def initialize(self): QApplication.setOverrideCursor(Qt.WaitCursor) self.thread = threading.Thread(target=self.startThread) self.thread.setDaemon(True) self.thread.start() def startThread(self): sleep(3) # this is instead of the initialization wait self.threadDone.emit() def onThreadDone(self): self.thread.join() QApplication.restoreOverrideCursor()The only way I was able to get correct cursor was if I have a join() call right after the thread start() (see below). Once thread is joined this way, cursor is restored back to the Arrow one. The problem with this implementation is that it looks identical to the one without the thread to start with. User has to wait couple of seconds for the initialization to complete and it is pretty annoying.
def initialize(self): QApplication.setOverrideCursor(Qt.WaitCursor) self.thread = threading.Thread(target=self.startThread) self.thread.setDaemon(True) self.thread.start() self.thread.join() QApplication.restoreOverrideCursor()