QtBase
v6.3.1
|
The QAbstractButton class is the abstract base class of button widgets, providing functionality common to buttons. More...
#include <qabstractbutton.h>
Public Slots | |
void | setIconSize (const QSize &size) |
void | animateClick () |
void | click () |
void | toggle () |
void | setChecked (bool) |
Public Slots inherited from QWidget | |
void | setEnabled (bool) |
void | setDisabled (bool) |
void | setWindowModified (bool) |
void | setWindowTitle (const QString &) |
void | setStyleSheet (const QString &styleSheet) |
void | setFocus () |
void | update () |
void | repaint () |
virtual void | setVisible (bool visible) |
void | setHidden (bool hidden) |
void | show () |
void | hide () |
void | showMinimized () |
void | showMaximized () |
void | showFullScreen () |
void | showNormal () |
bool | close () |
void | raise () |
void | lower () |
Public Slots inherited from QObject | |
void | deleteLater () |
Signals | |
void | pressed () |
void | released () |
void | clicked (bool checked=false) |
void | toggled (bool checked) |
Signals inherited from QWidget | |
void | windowTitleChanged (const QString &title) |
void | windowIconChanged (const QIcon &icon) |
void | windowIconTextChanged (const QString &iconText) |
void | customContextMenuRequested (const QPoint &pos) |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
Properties | |
QString | text |
the text shown on the button More... | |
QIcon | icon |
the icon shown on the button More... | |
QSize | iconSize |
the icon size used for this button. More... | |
QKeySequence | shortcut |
the mnemonic associated with the button More... | |
bool | checkable |
whether the button is checkable More... | |
bool | checked |
whether the button is checked More... | |
bool | autoRepeat |
whether autoRepeat is enabled More... | |
bool | autoExclusive |
whether auto-exclusivity is enabled More... | |
int | autoRepeatDelay |
the initial delay of auto-repetition More... | |
int | autoRepeatInterval |
the interval of auto-repetition More... | |
bool | down |
whether the button is pressed down More... | |
Properties inherited from QWidget | |
bool | modal |
whether the widget is a modal widget More... | |
Qt::WindowModality | windowModality |
which windows are blocked by the modal widget More... | |
bool | enabled |
whether the widget is enabled More... | |
QRect | geometry |
the geometry of the widget relative to its parent and excluding the window frame More... | |
QRect | frameGeometry |
geometry of the widget relative to its parent including any window frame More... | |
QRect | normalGeometry |
the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) top-level widget More... | |
int | x |
the x coordinate of the widget relative to its parent including any window frame More... | |
int | y |
the y coordinate of the widget relative to its parent and including any window frame More... | |
QPoint | pos |
the position of the widget within its parent widget More... | |
QSize | frameSize |
the size of the widget including any window frame More... | |
QSize | size |
the size of the widget excluding any window frame More... | |
int | width |
the width of the widget excluding any window frame More... | |
int | height |
the height of the widget excluding any window frame More... | |
QRect | rect |
the internal geometry of the widget excluding any window frame More... | |
QRect | childrenRect |
the bounding rectangle of the widget's children More... | |
QRegion | childrenRegion |
the combined region occupied by the widget's children More... | |
QSizePolicy | sizePolicy |
the default layout behavior of the widget More... | |
QSize | minimumSize |
the widget's minimum size More... | |
QSize | maximumSize |
the widget's maximum size in pixels More... | |
int | minimumWidth |
the widget's minimum width in pixels More... | |
int | minimumHeight |
the widget's minimum height in pixels More... | |
int | maximumWidth |
the widget's maximum width in pixels More... | |
int | maximumHeight |
the widget's maximum height in pixels More... | |
QSize | sizeIncrement |
the size increment of the widget More... | |
QSize | baseSize |
the base size of the widget More... | |
QPalette | palette |
the widget's palette More... | |
QFont | font |
the font currently set for the widget More... | |
QCursor | cursor |
the cursor shape for this widget More... | |
bool | mouseTracking |
whether mouse tracking is enabled for the widget More... | |
bool | tabletTracking |
whether tablet tracking is enabled for the widget More... | |
bool | isActiveWindow |
whether this widget's window is the active window More... | |
Qt::FocusPolicy | focusPolicy |
the way the widget accepts keyboard focus More... | |
bool | focus |
whether this widget (or its focus proxy) has the keyboard input focus More... | |
Qt::ContextMenuPolicy | contextMenuPolicy |
how the widget shows a context menu More... | |
bool | updatesEnabled |
whether updates are enabled More... | |
bool | visible |
whether the widget is visible More... | |
bool | minimized |
whether this widget is minimized (iconified) More... | |
bool | maximized |
whether this widget is maximized More... | |
bool | fullScreen |
whether the widget is shown in full screen mode More... | |
QSize | sizeHint |
the recommended size for the widget More... | |
QSize | minimumSizeHint |
the recommended minimum size for the widget More... | |
bool | acceptDrops |
whether drop events are enabled for this widget More... | |
QString | windowTitle |
the window title (caption) More... | |
QIcon | windowIcon |
the widget's icon More... | |
QString | windowIconText |
the text to be displayed on the icon of a minimized window More... | |
double | windowOpacity |
The level of opacity for the window. More... | |
bool | windowModified |
whether the document shown in the window has unsaved changes More... | |
QString | accessibleName |
the widget's name as seen by assistive technologies More... | |
QString | accessibleDescription |
the widget's description as seen by assistive technologies More... | |
Qt::LayoutDirection | layoutDirection |
the layout direction for this widget. More... | |
bool | autoFillBackground |
whether the widget background is filled automatically More... | |
QString | styleSheet |
the widget's style sheet More... | |
QLocale | locale |
the widget's locale More... | |
QString | windowFilePath |
the file path associated with a widget More... | |
Qt::InputMethodHints | inputMethodHints |
What input method specific hints the widget has. More... | |
Properties inherited from QObject | |
QString | objectName |
the name of this object More... | |
Friends | |
class | QButtonGroup |
The QAbstractButton class is the abstract base class of button widgets, providing functionality common to buttons.
\inmodule QtWidgets
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:
The \uicontrol Alt+C shortcut is assigned to the button, i.e., when the user presses \uicontrol Alt+C the button will call animateClick(). See the \l {QShortcut::mnemonic}{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, and therefore can't have any automatic shortcut.
All the buttons provided by Qt (QPushButton, QToolButton, QCheckBox, and QRadioButton) can display both \l text and \l{icon}{icons}.
A button can be made the default button in a dialog by means of QPushButton::setDefault() and QPushButton::setAutoDefault().
QAbstractButton provides most of the states used for buttons:
\list
\endlist
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:
\list 1
\endlist
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().
Definition at line 58 of file qabstractbutton.h.
Constructs an abstract button with a parent.
Definition at line 469 of file qabstractbutton.cpp.
QAbstractButton::~QAbstractButton | ( | ) |
Destroys the button.
Definition at line 479 of file qabstractbutton.cpp.
|
protected |
Definition at line 491 of file qabstractbutton.cpp.
|
slot |
Performs an animated click: the button is pressed immediately, and released 100ms later.
Calling this function again before the button is released resets the release timer.
All signals associated with a click are emitted as appropriate.
This function does nothing if the button is \l{setEnabled()}{disabled.}
Definition at line 832 of file qabstractbutton.cpp.
bool QAbstractButton::autoExclusive | ( | ) | const |
Definition at line 797 of file qabstractbutton.cpp.
bool QAbstractButton::autoRepeat | ( | ) | const |
Definition at line 720 of file qabstractbutton.cpp.
int QAbstractButton::autoRepeatDelay | ( | ) | const |
Definition at line 743 of file qabstractbutton.cpp.
int QAbstractButton::autoRepeatInterval | ( | ) | const |
Definition at line 766 of file qabstractbutton.cpp.
\reimp
Reimplemented from QWidget.
Reimplemented in QToolButton.
Definition at line 1180 of file qabstractbutton.cpp.
|
protectedvirtual |
This virtual handler is called when setChecked() is used, unless it is called from within nextCheckState(). It allows subclasses to reset their intermediate button states.
Reimplemented in QToolButton, and QCheckBox.
Definition at line 894 of file qabstractbutton.cpp.
|
slot |
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 \l{setEnabled()}{disabled.}
Definition at line 857 of file qabstractbutton.cpp.
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.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Reimplemented in QDockWidgetTitleButton, QToolButton, QToolBarExtension, QRadioButton, QPushButton, QCommandLinkButton, and QCheckBox.
Definition at line 925 of file qabstractbutton.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Reimplemented in SpecialRadioButton, and QPushButton.
Definition at line 1158 of file qabstractbutton.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Reimplemented in QPushButton.
Definition at line 1169 of file qabstractbutton.cpp.
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 in TestPushButton, TestButton, QToolButton, QPushButton, QCheckBox, TestPushButton, and QRadioButton.
Definition at line 919 of file qabstractbutton.cpp.
QIcon QAbstractButton::icon | ( | ) | const |
Definition at line 557 of file qabstractbutton.cpp.
QSize QAbstractButton::iconSize | ( | ) | const |
bool QAbstractButton::isCheckable | ( | ) | const |
bool QAbstractButton::isChecked | ( | ) | const |
bool QAbstractButton::isDown | ( | ) | const |
\reimp
Reimplemented from QWidget.
Reimplemented in QPushButton.
Definition at line 1042 of file qabstractbutton.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Reimplemented in QRadioButton, QPushButton, and QCheckBox.
Definition at line 1020 of file qabstractbutton.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Reimplemented in QToolButton.
Definition at line 972 of file qabstractbutton.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Reimplemented in QToolButton.
Definition at line 991 of file qabstractbutton.cpp.
|
protectedvirtual |
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.
Reimplemented in QToolButton, and QCheckBox.
Definition at line 905 of file qabstractbutton.cpp.
|
overrideprotectedpure virtual |
\reimp
Reimplemented from QWidget.
Implemented in QT_BEGIN_NAMESPACE::CloseButton, QDockWidgetTitleButton, MyButton, QToolButton, QToolBoxButton, QToolBarExtension, QRadioButton, QPushButton, QMenuBarExtension, QCommandLinkButton, QCheckBox, and MyPushButton.
|
signal |
This signal is emitted when the button is pressed down.
|
signal |
void QAbstractButton::setAutoExclusive | ( | bool | autoExclusive | ) |
Definition at line 791 of file qabstractbutton.cpp.
void QAbstractButton::setAutoRepeat | ( | bool | autoRepeat | ) |
void QAbstractButton::setAutoRepeatDelay | ( | int | autoRepeatDelay | ) |
void QAbstractButton::setAutoRepeatInterval | ( | int | autoRepeatInterval | ) |
void QAbstractButton::setCheckable | ( | bool | checkable | ) |
|
slot |
Definition at line 617 of file qabstractbutton.cpp.
void QAbstractButton::setDown | ( | bool | down | ) |
Definition at line 548 of file qabstractbutton.cpp.
Definition at line 1278 of file qabstractbutton.cpp.
void QAbstractButton::setShortcut | ( | const QKeySequence & | key | ) |
Definition at line 569 of file qabstractbutton.cpp.
Definition at line 515 of file qabstractbutton.cpp.
QKeySequence QAbstractButton::shortcut | ( | ) | const |
Definition at line 578 of file qabstractbutton.cpp.
QString QAbstractButton::text | ( | ) | const |
|
overrideprotectedvirtual |
\reimp
Reimplemented from QObject.
Reimplemented in QToolButton.
Definition at line 1136 of file qabstractbutton.cpp.
|
slot |
Toggles the state of a checkable button.
Definition at line 881 of file qabstractbutton.cpp.
|
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() is 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:
Button groups can be created using the QButtonGroup class, and updates to the button states monitored with the \l{QButtonGroup::buttonClicked()} signal.
|
friend |
Definition at line 154 of file qabstractbutton.h.
|
readwrite |
whether auto-exclusivity is enabled
If auto-exclusivity is enabled, checkable buttons that belong to the same parent widget behave as if they were part of the same exclusive button group. In an exclusive button group, only one button can be checked at any time; checking another button automatically unchecks the previously checked one.
The property has no effect on buttons that belong to a button group.
autoExclusive is off by default, except for radio buttons.
Definition at line 157 of file qabstractbutton.h.
|
readwrite |
whether autoRepeat is enabled
If autoRepeat is enabled, then the pressed(), released(), and clicked() signals are emitted at regular intervals when the button is down. autoRepeat is off by default. The initial delay and the repetition interval are defined in milliseconds by \l autoRepeatDelay and \l autoRepeatInterval.
Note: If a button is pressed down by a shortcut key, then auto-repeat is enabled and timed by the system and not by this class. The pressed(), released(), and clicked() signals will be emitted like in the normal case.
Definition at line 157 of file qabstractbutton.h.
|
readwrite |
the initial delay of auto-repetition
If \l autoRepeat is enabled, then autoRepeatDelay defines the initial delay in milliseconds before auto-repetition kicks in.
Definition at line 157 of file qabstractbutton.h.
|
readwrite |
the interval of auto-repetition
If \l autoRepeat is enabled, then autoRepeatInterval defines the length of the auto-repetition interval in millisecons.
Definition at line 157 of file qabstractbutton.h.
|
readwrite |
whether the button is checkable
By default, the button is not checkable.
Definition at line 157 of file qabstractbutton.h.
|
readwrite |
whether the button is checked
Only checkable buttons can be checked. By default, the button is unchecked.
Definition at line 157 of file qabstractbutton.h.
|
readwrite |
whether the button is pressed down
If this property is true
, the button is pressed down. The signals pressed() and clicked() are not emitted if you set this property to true. The default is false.
Definition at line 157 of file qabstractbutton.h.
|
readwrite |
the icon shown on the button
The icon's default size is defined by the GUI style, but can be adjusted by setting the \l iconSize property.
Definition at line 157 of file qabstractbutton.h.
|
readwrite |
the icon size used for this button.
The default size is defined by the GUI style. This is a maximum size for the icons. Smaller icons will not be scaled up.
Definition at line 157 of file qabstractbutton.h.
|
readwrite |
the mnemonic associated with the button
Definition at line 157 of file qabstractbutton.h.
|
readwrite |
the text shown on the button
If the button has no text, the text() function will return an empty string.
If the text contains an ampersand character ('&'), a shortcut is automatically created for it. The character that follows the '&' will be used as the shortcut key. Any previous shortcut will be overwritten or cleared if no shortcut is defined by the text. See the \l {QShortcut::mnemonic}{QShortcut} documentation for details. To display an actual ampersand, use '&&'.
There is no default text.
Definition at line 157 of file qabstractbutton.h.