QDialog: how to use question mark (?) button?

前端 未结 3 654
逝去的感伤
逝去的感伤 2021-01-12 01:39

By default, QDialog windows have a question mark pushbutton in the upper-right corner. When I press it, the mouse cursor is changed to the \'Forbidden\' cursor,

3条回答
  •  灰色年华
    2021-01-12 02:00

    Based on Chernobyl's answer, this is how I did it in Python (PySide):

    def event(self, event): 
        if event.type() == QtCore.QEvent.EnterWhatsThisMode:
            print "click"
            return True
        return QtGui.QDialog.event(self, event)
    

    That is, you reimplement event when app enters 'WhatsThisMode'. Otherwise, pass along control back to the base class.

    It almost works. The only wrinkle is that the mouse cursor is still turned into the 'Forbidden' shape. Based on another post, I got rid of that by adding:

    QtGui.QWhatsThis.leaveWhatsThisMode()
    

    As the line right before the print command in the previous.

提交回复
热议问题