9

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, and nothing else seems to happen.

While there is lots of information generated from those who want to remove the question mark (at least three SO threads are devoted to the topic), the documentation for QDialog doesn't have anything about how to actually use it.

How do I get my application to display information when the question mark is clicked? E.g., how do I get the clicked signal from the button? Better yet, where is this button documented?

Community
  • 1
  • 1
eric
  • 7,142
  • 12
  • 72
  • 138

3 Answers3

12

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

When this button is clicked and WhatsThisMode is triggered, the elements of the dialog are supposed to give info about themselves. And if mouse hovers over an element that supports this info then the pointer will become a pointing arrow with a question mark (on Windows at least), with a tooltip message displayed on mouse click.

Here's how to achieve it in PySide:

someWidget.setWhatsThis("Help on widget")

QWhatsThis documentation for PySide and Qt5 is also available.

eric
  • 7,142
  • 12
  • 72
  • 138
Andris
  • 921
  • 7
  • 14
  • This is great, you are right the above answers focus on an idiosyncratic use, thanks for pointing out the standard use, and documentation! – eric Apr 23 '16 at 12:54
  • I have seen what's this attribute in qt designer, so you can manage and from there. – Chris P Oct 02 '21 at 20:03
3

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

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

There are different types as QEvent::EnterWhatsThisMode QEvent::WhatsThisClicked and so on. I achieved something similar to what are you looking for using event filter in mainwindow.

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

I saw "click" when I clicked on ? button.

silver est
  • 51
  • 6
Jablonski
  • 18,083
  • 2
  • 46
  • 47
  • @Chrnobyl cool...now I need to figure out how to stop it from displaying the 'Forbidden' mouse cursor shape--makes it seem like the button was pressed in error (pretty strange default behavior, imo). – eric Nov 17 '14 at 15:56
  • @neuronet 'Forbidden' mouse cursor should be on every widget which does not support whatsThis, so it is normal, or did I misunderstand you? – Jablonski Nov 17 '14 at 16:25
  • Even after I reimplement event, Forbidden cursor still is locked on. Similar even when I add `QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))` to the event handler: temporarily shows as arrow, but Forbidden cursor comes back when cursor leaves the Title Bar. I plan to ask about this as a separate question... – eric Nov 17 '14 at 16:35
  • Asked about it here: http://stackoverflow.com/questions/26977603/qdialog-forbidden-cursor-with-question-mark-press – eric Nov 17 '14 at 16:47
1

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.

Community
  • 1
  • 1
eric
  • 7,142
  • 12
  • 72
  • 138