QWhatsThis

The QWhatsThis class provides a simple description of any widget, i.e. answering the question 鈥淲hat鈥檚 This?鈥. More

Inheritance diagram of PySide2.QtWidgets.QWhatsThis

Synopsis

Static functions

Detailed Description

鈥淲hat鈥檚 This?鈥 help is part of an application鈥檚 online help system, and provides users with information about the functionality and usage of a particular widget. 鈥淲hat鈥檚 This?鈥 help texts are typically longer and more detailed than tooltips , but generally provide less information than that supplied by separate help windows.

QWhatsThis provides a single window with an explanatory text that pops up when the user asks 鈥淲hat鈥檚 This?鈥. The default way for users to ask the question is to move the focus to the relevant widget and press Shift+F1. The help text appears immediately; it goes away as soon as the user does something else. (Note that if there is a shortcut for Shift+F1, this mechanism will not work.) Some dialogs provide a 鈥?鈥 button that users can click to enter 鈥淲hat鈥檚 This?鈥 mode; they then click the relevant widget to pop up the 鈥淲hat鈥檚 This?鈥 window. It is also possible to provide a a menu option or toolbar button to switch into 鈥淲hat鈥檚 This?鈥 mode.

To add 鈥淲hat鈥檚 This?鈥 text to a widget or an action, you simply call setWhatsThis() or setWhatsThis() .

The text can be either rich text or plain text. If you specify a rich text formatted string, it will be rendered using the default stylesheet, making it possible to embed images in the displayed text. To be as fast as possible, the default stylesheet uses a simple method to determine whether the text can be rendered as plain text. See mightBeRichText() for details.

Act = QAction(tr("&New"), self)
Act.setShortcut(tr("Ctrl+N"))
Act.setStatusTip(QObject.tr("Create a new file"))
Act.setWhatsThis(QObject.tr("Click self option to create a new file."))

An alternative way to enter 鈥淲hat鈥檚 This?鈥 mode is to call createAction() , and add the returned QAction to either a menu or a tool bar. By invoking this context help action (in the picture below, the button with the arrow and question mark icon) the user switches into 鈥淲hat鈥檚 This?鈥 mode. If they now click on a widget the appropriate help text is shown. The mode is left when help is given or when the user presses Esc.

../../_images/whatsthis.png

You can enter 鈥淲hat鈥檚 This?鈥 mode programmatically with enterWhatsThisMode() , check the mode with inWhatsThisMode() , and return to normal mode with leaveWhatsThisMode() .

If you want to control the 鈥淲hat鈥檚 This?鈥 behavior of a widget manually see WA_CustomWhatsThis .

It is also possible to show different help texts for different regions of a widget, by using a QHelpEvent of type WhatsThis . Intercept the help event in your widget鈥檚 event() function and call showText() with the text you want to display for the position specified in pos() . If the text is rich text and the user clicks on a link, the widget also receives a QWhatsThisClickedEvent with the link鈥檚 reference as href() . If a QWhatsThisClickedEvent is handled (i.e. event() returns true), the help window remains visible. Call hideText() to hide it explicitly.

See also

QToolTip

class PySide2.QtWidgets.QWhatsThis
static PySide2.QtWidgets.QWhatsThis.createAction([parent=None])
Parameters:

parentPySide2.QtCore.QObject

Return type:

PySide2.QtWidgets.QAction

Returns a ready-made QAction , used to invoke 鈥淲hat鈥檚 This?鈥 context help, with the given parent .

The returned QAction provides a convenient way to let users enter 鈥淲hat鈥檚 This?鈥 mode.

static PySide2.QtWidgets.QWhatsThis.enterWhatsThisMode()

This function switches the user interface into 鈥淲hat鈥檚 This?鈥 mode. The user interface can be switched back into normal mode by the user (e.g. by them clicking or pressing Esc), or programmatically by calling leaveWhatsThisMode() .

When entering 鈥淲hat鈥檚 This?鈥 mode, a QEvent of type Qt::EnterWhatsThisMode is sent to all toplevel widgets.

static PySide2.QtWidgets.QWhatsThis.hideText()

If a 鈥淲hat鈥檚 This?鈥 window is showing, this destroys it.

See also

showText()

static PySide2.QtWidgets.QWhatsThis.inWhatsThisMode()
Return type:

bool

Returns true if the user interface is in 鈥淲hat鈥檚 This?鈥 mode; otherwise returns false .

static PySide2.QtWidgets.QWhatsThis.leaveWhatsThisMode()

If the user interface is in 鈥淲hat鈥檚 This?鈥 mode, this function switches back to normal mode; otherwise it does nothing.

When leaving 鈥淲hat鈥檚 This?鈥 mode, a QEvent of type Qt::LeaveWhatsThisMode is sent to all toplevel widgets.

static PySide2.QtWidgets.QWhatsThis.showText(pos, text[, w=None])
Parameters:

Shows text as a 鈥淲hat鈥檚 This?鈥 window, at global position pos . The optional widget argument, w , is used to determine the appropriate screen on multi-head systems.

See also

hideText()