PySide6.QtWidgets.QAbstractButton¶
- class QAbstractButton¶
- The - QAbstractButtonclass is the abstract base class of button widgets, providing functionality common to buttons. More…- Inherited by: - QToolButton,- QRadioButton,- QPushButton,- QCommandLinkButton,- QCheckBox- Synopsis¶- Properties¶- autoExclusiveᅟ- Whether auto-exclusivity is enabled
- autoRepeatᅟ- Whether autoRepeat is enabled
- autoRepeatDelayᅟ- The initial delay of auto-repetition
- autoRepeatIntervalᅟ- The interval of auto-repetition
- checkableᅟ- Whether the button is checkable
- checkedᅟ- Whether the button is checked
- downᅟ- Whether the button is pressed down
- iconᅟ- The icon shown on the button
- iconSizeᅟ- The icon size used for this button
- shortcutᅟ- The mnemonic associated with the button
- textᅟ- The text shown on the button
 - Methods¶- def - __init__()
- def - autoExclusive()
- def - autoRepeat()
- def - group()
- def - icon()
- def - iconSize()
- def - isCheckable()
- def - isChecked()
- def - isDown()
- def - setAutoRepeat()
- def - setCheckable()
- def - setDown()
- def - setIcon()
- def - setShortcut()
- def - setText()
- def - shortcut()
- def - text()
 - Virtual methods¶- def - checkStateSet()
- def - hitButton()
- def - nextCheckState()
 - Slots¶- def - animateClick()
- def - click()
- def - setChecked()
- def - setIconSize()
- def - toggle()
 - Signals¶- def - clicked()
- def - pressed()
- def - released()
- def - toggled()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - This class implements an abstract button. Subclasses of this class handle user actions, and specify how the button is drawn. - QAbstractButtonprovides support for both push buttons and checkable (toggle) buttons. Checkable buttons are implemented in the- QRadioButtonand- QCheckBoxclasses. Push buttons are implemented in the- QPushButtonand- QToolButtonclasses; 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 (’&’), - QAbstractButtonautomatically creates a shortcut key. For example:- button = QPushButton(tr("Rock and Roll"), self) - 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, and therefore can’t have any automatic shortcut.- button.setIcon(QIcon(":/images/print.png")) button.setShortcut(tr("Alt+F7")) - All the buttons provided by Qt ( - QPushButton,- QToolButton,- QCheckBox, and- QRadioButton) can display both- textand- icons.- A button can be made the default button in a dialog by means of - setDefault()and- setAutoDefault().- QAbstractButtonprovides most of the states used for buttons:- isDown()indicates whether the button is pressed down.
- isChecked()indicates whether the button is checked. Only checkable buttons can be checked and unchecked (see below).
- isEnabled()indicates whether the button can be pressed by the user.- Note - As opposed to other widgets, buttons derived from - QAbstractButtonaccept mouse and context menu events when disabled.
- setAutoRepeat()sets whether the button will auto-repeat if the user holds it down.- autoRepeatDelayand- autoRepeatIntervaldefine how auto-repetition is done.
- setCheckable()sets whether the button is a toggle button or not.
 - 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).- QAbstractButtonprovides four signals:- pressed()is emitted when the left mouse button is pressed while the mouse cursor is inside the button.
- released()is emitted when the left mouse button is released.
- clicked()is emitted when the button is first pressed and then released, when the shortcut key is typed, or when- click()or- animateClick()is called.
- toggled()is emitted when the state of a toggle button changes.
 - 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().- See also - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property autoExclusiveᅟ: bool¶
 - This property holds 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. - See also - Access functions:
 - property autoRepeatᅟ: bool¶
 - This property holds 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- autoRepeatDelayand- 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.- Access functions:
 - property autoRepeatDelayᅟ: int¶
 - This property holds the initial delay of auto-repetition. - If - autoRepeatis enabled, then autoRepeatDelay defines the initial delay in milliseconds before auto-repetition kicks in.- See also - Access functions:
 - property autoRepeatIntervalᅟ: int¶
 - This property holds the interval of auto-repetition. - If - autoRepeatis enabled, then autoRepeatInterval defines the length of the auto-repetition interval in millisecons.- See also - Access functions:
 - property checkableᅟ: bool¶
 - This property holds whether the button is checkable. - By default, the button is not checkable. - See also - checked- Access functions:
 - property checkedᅟ: bool¶
 - This property holds whether the button is checked. - Only checkable buttons can be checked. By default, the button is unchecked. - See also - checkable- Access functions:
- Signal - toggled()
 
 - property downᅟ: bool¶
 - This property holds 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.- This property holds the icon shown on the button. - The icon’s default size is defined by the GUI style, but can be adjusted by setting the - iconSizeproperty.- This property holds 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. - Access functions:
 - property shortcutᅟ: QKeySequence¶
 - This property holds the mnemonic associated with the button. - Access functions:
 - property textᅟ: str¶
 - This property holds 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 QShortcut documentation for details. To display an actual ampersand, use ‘&&’. - There is no default text. - Constructs an abstract button with a - parent.- animateClick()¶
 - 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 - PySide6.QtWidgets.QWidget.setEnabled()- See also - autoExclusive()¶
- Return type:
- bool 
 - See also 
 - Getter of property - autoExclusiveᅟ.- autoRepeat()¶
- Return type:
- bool 
 - See also 
 - Getter of property - autoRepeatᅟ.- autoRepeatDelay()¶
- Return type:
- int 
 - See also 
 - Getter of property - autoRepeatDelayᅟ.- autoRepeatInterval()¶
- Return type:
- int 
 - See also 
 - Getter of property - autoRepeatIntervalᅟ.- checkStateSet()¶
 - 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.- See also - 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 - PySide6.QtWidgets.QWidget.setEnabled()- See also - clicked([checked=false])¶
- Parameters:
- checked – bool 
 
 - 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, - checkedis true if the button is checked, or false if the button is unchecked.- See also - group()¶
- Return type:
 
 - Returns the group that this button belongs to. - If the button is not a member of any - QButtonGroup, this function returns- None.- See also - Returns - trueif- posis 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. - Getter of property - iconᅟ.- iconSize()¶
- Return type:
 - See also 
 - Getter of property - iconSizeᅟ.- isCheckable()¶
- Return type:
- bool 
 
 - Getter of property - checkableᅟ.- isChecked()¶
- Return type:
- bool 
 
 - Getter of property - checkedᅟ.- isDown()¶
- Return type:
- bool 
 
 - Getter of property - downᅟ.- nextCheckState()¶
 - 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 - pressed()¶
 - This signal is emitted when the button is pressed down. - See also - released()¶
 - This signal is emitted when the button is released. - setAutoExclusive(arg__1)¶
- Parameters:
- arg__1 – bool 
 - See also 
 - Setter of property - autoExclusiveᅟ.- setAutoRepeat(arg__1)¶
- Parameters:
- arg__1 – bool 
 - See also 
 - Setter of property - autoRepeatᅟ.- setAutoRepeatDelay(arg__1)¶
- Parameters:
- arg__1 – int 
 - See also 
 - Setter of property - autoRepeatDelayᅟ.- setAutoRepeatInterval(arg__1)¶
- Parameters:
- arg__1 – int 
 - See also 
 - Setter of property - autoRepeatIntervalᅟ.- setCheckable(arg__1)¶
- Parameters:
- arg__1 – bool 
 - See also 
 - Setter of property - checkableᅟ.- setChecked(arg__1)¶
- Parameters:
- arg__1 – bool 
 - See also 
 - Setter of property - checkedᅟ.- Setter of property - downᅟ.- Setter of property - iconᅟ.- Setter of property - iconSizeᅟ.- setShortcut(key)
- Parameters:
- key – - QKeySequence
 - See also 
 - Setter of property - shortcutᅟ.- Setter of property - textᅟ.- shortcut()¶
- Return type:
 - See also 
 - Getter of property - shortcutᅟ.- Getter of property - textᅟ.- toggle()¶
 - Toggles the state of a checkable button. - See also - checked- toggled(checked)¶
- Parameters:
- checked – bool 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - This signal is emitted whenever a checkable button changes its state. - checkedis 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: - def reactToToggle(self, checked): if checked: # Examine the new button states. ... - Button groups can be created using the - QButtonGroupclass, and updates to the button states monitored with the- buttonClicked()signal.- See also - checked- clicked()- Notification signal of property - checkedᅟ.