问题
I am trying to get the 'WhatsThis' functionality working in a QDialog-based application, so when the user clicks the little question mark in the Title Bar, a little 'about' dialog appears.
By default, clicking that button does nothing except change my mouse cursor to the 'Forbidden' cursor:

Based on a previous post, I reimplemented event as follows:
def event(self, event):
if event.type() == QtCore.QEvent.EnterWhatsThisMode:
print "Here is a useful message"
return True
return QtGui.QDialog.event(self, event)
While this prints out the desired message, I still get the 'Forbidden' cursor, even when I add the following to the above event function:
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
This creates an arrow temporarily, but when I bring the cursor anywhere outside the Title Bar in the app, the cursor turns Forbidden again. It's almost as if it is acting like there is a modal dialog open somewhere that needs to be executed.
How can I stop this Forbidden behavior?
回答1:
Insert a call to QWhatsThis.leaveWhatsThisMode() in your event handler to exit "What's this?" mode as soon as it's entered.
def event(self, event):
if event.type() == QtCore.QEvent.EnterWhatsThisMode:
QtGui.QWhatsThis.leaveWhatsThisMode()
print "Here is a useful message"
return True
return QtGui.QDialog.event(self, event)
来源:https://stackoverflow.com/questions/26977603/qdialog-forbidden-cursor-appears-when-question-mark-pressed