Home · All Classes · Modules |
The QAbstractButton class is the abstract base class of button widgets, providing functionality common to buttons. More...
Inherits QWidget.
Inherited by QCheckBox, QPushButton, QRadioButton and QToolButton.
The QAbstractButton class is the abstract base class of button widgets, providing functionality common to buttons.
This class implements an abstract button. Subclasses of this class handle user actions, and specify how the button is drawn.
QAbstractButton provides support for both push buttons and checkable (toggle) buttons. Checkable buttons are implemented in the QRadioButton and QCheckBox classes. Push buttons are implemented in the QPushButton and QToolButton classes; these also provide toggle behavior if required.
Any button can display a label containing text and an icon. setText() sets the text; setIcon() sets the icon. If a button is disabled, its label is changed to give the button a "disabled" appearance.
If the button is a text button with a string containing an ampersand ('&'), QAbstractButton automatically creates a shortcut key. For example:
QPushButton *button = new QPushButton(tr("Ro&ck && Roll"), this);
The Alt+C shortcut is assigned to the button, i.e., when the user presses Alt+C the button will call animateClick(). See the QShortcut documentation for details (to display an actual ampersand, use '&&').
You can also set a custom shortcut key using the setShortcut() function. This is useful mostly for buttons that do not have any text, because they have no automatic shortcut.
button->setIcon(QIcon(":/images/print.png")); button->setShortcut(tr("Alt+F7"));
All of the buttons provided by Qt (QPushButton, QToolButton, QCheckBox, and QRadioButton) can display both text and icons.
A button can be made the default button in a dialog are provided by QPushButton.setDefault() and QPushButton.setAutoDefault().
QAbstractButton provides most of the states used for buttons:
The difference between isDown() and isChecked() is as follows. When the user clicks a toggle button to check it, the button is first pressed then released into the checked state. When the user clicks it again (to uncheck it), the button moves first to the pressed state, then to the unchecked state (isChecked() and isDown() are both false).
QAbstractButton provides four signals:
To subclass QAbstractButton, you must reimplement at least paintEvent() to draw the button's outline and its text or pixmap. It is generally advisable to reimplement sizeHint() as well, and sometimes hitButton() (to determine whether a button press is within the button). For buttons with more than two states (like tri-state buttons), you will also have to reimplement checkStateSet() and nextCheckState().
The parent argument, if not None, causes self to be owned by Qt instead of PyQt.
Constructs an abstract button with a parent.
This method is also a Qt slot with the C++ signature void animateClick(int = 100).
Performs an animated click: the button is pressed immediately, and released msec milliseconds later (the default is 100 ms).
Calling this function again before the button was released will reset the release timer.
All signals associated with a click are emitted as appropriate.
This function does nothing if the button is disabled.
See also click().
Reimplemented from QWidget.changeEvent().
This virtual handler is called when setChecked() was called, unless it was called from within nextCheckState(). It allows subclasses to reset their intermediate button states.
See also nextCheckState().
This method is also a Qt slot with the C++ signature void click().
Performs a click.
All the usual signals associated with a click are emitted as appropriate. If the button is checkable, the state of the button is toggled.
This function does nothing if the button is disabled.
See also animateClick().
Reimplemented from QObject.event().
Reimplemented from QWidget.focusInEvent().
Reimplemented from QWidget.focusOutEvent().
Returns the group that this button belongs to.
If the button is not a member of any QButtonGroup, this function returns 0.
See also QButtonGroup.
Returns true if pos is inside the clickable button rectangle; otherwise returns false.
By default, the clickable area is the entire widget. Subclasses may reimplement this function to provide support for clickable areas of different shapes and sizes.
Reimplemented from QWidget.keyPressEvent().
Reimplemented from QWidget.keyReleaseEvent().
Reimplemented from QWidget.mouseMoveEvent().
Reimplemented from QWidget.mousePressEvent().
Reimplemented from QWidget.mouseReleaseEvent().
This virtual handler is called when a button is clicked. The default implementation calls setChecked(!isChecked()) if the button isCheckable(). It allows subclasses to implement intermediate button states.
See also checkStateSet().
This method is abstract and should be reimplemented in any sub-class.
Reimplemented from QWidget.paintEvent().
This method is also a Qt slot with the C++ signature void setChecked(bool).
This method is also a Qt slot with the C++ signature void setIconSize(const ::QSize&).
Reimplemented from QObject.timerEvent().
This method is also a Qt slot with the C++ signature void toggle().
Toggles the state of a checkable button.
See also checked.
This is the default overload of this signal.
This signal is emitted when the button is activated (i.e. pressed down then released while the mouse cursor is inside the button), when the shortcut key is typed, or when click() or animateClick() is called. Notably, this signal is not emitted if you call setDown(), setChecked() or toggle().
If the button is checkable, checked is true if the button is checked, or false if the button is unchecked.
See also pressed(), released(), and toggled().
This is the default overload of this signal.
This signal is emitted when the button is pressed down.
See also released() and clicked().
This is the default overload of this signal.
This signal is emitted when the button is released.
See also pressed(), clicked(), and toggled().
This is the default overload of this signal.
This signal is emitted whenever a checkable button changes its state. checked is true if the button is checked, or false if the button is unchecked.
This may be the result of a user action, click() slot activation, or because setChecked() was called.
The states of buttons in exclusive button groups are updated before this signal is emitted. This means that slots can act on either the "off" signal or the "on" signal emitted by the buttons in the group whose states have changed.
For example, a slot that reacts to signals emitted by newly checked buttons but which ignores signals from buttons that have been unchecked can be implemented using the following pattern:
void MyWidget.reactToToggle(bool checked) { if (checked) { // Examine the new button states. ... } }
Button groups can be created using the QButtonGroup class, and updates to the button states monitored with the QButtonGroup.buttonClicked() signal.
See also checked and clicked().
PyQt 4.12.1 for X11 | Copyright © Riverbank Computing Ltd and The Qt Company 2015 | Qt 4.8.7 |