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

By default, windows QDialoghave a question mark button in the upper right corner. When I click on it, the mouse cursor changes to the "Forbidden" cursor, and nothing else happens.

As long as there is a lot of information received from those who want to remove the question mark ( the least three SO topics are dedicated to the topic), the documentation for QDialog doesn’t 'I have anything about how to use it.

How do I get my application to display information when I click a question mark? For example, how do I get a signal clickedfrom a button? Better yet, where is this button documented?

+4
source share
3 answers

This is not a button documented by Qt. You can detect this by catching events and checking the type of event:

http://qt-project.org/doc/qt-5/qevent.html#Type-enum

There are different types QEvent::EnterWhatsThisMode QEvent::WhatsThisClicked, etc. I have achieved something similar to what you are looking for using the event filter in mainwindow.

if(event->type() == QEvent::EnterWhatsThisMode)
    qDebug() << "click";

I saw "click" when I pressed the button ?.

+3
source

The other answers were a bit misleading for me, focusing only on catching the event of the question, but not explaining the normal use.

WhatsThisMode, . , , - ( Windows) , .

PySide:

someWidget.setWhatsThis("Help on widget")

QWhatsThis PySide Qt5.

+5

, 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 redefine eventwhen the application enters "WhatsThisMode". Otherwise, go back to the base class.

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

QtGui.QWhatsThis.leaveWhatsThisMode()

Like the line before the print command in the previous one.

+1
source

All Articles