QAbstractButton

Inherited by: QPushButton, QCommandLinkButton, QCheckBox, QToolButton, QRadioButton

Synopsis

Functions

Virtual functions

Slots

Signals

Detailed Description

The PySide.QtGui.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.

PySide.QtGui.QAbstractButton provides support for both push buttons and checkable (toggle) buttons. Checkable buttons are implemented in the PySide.QtGui.QRadioButton and PySide.QtGui.QCheckBox classes. Push buttons are implemented in the PySide.QtGui.QPushButton and PySide.QtGui.QToolButton classes; these also provide toggle behavior if required.

Any button can display a label containing text and an icon. PySide.QtGui.QAbstractButton.setText() sets the text; PySide.QtGui.QAbstractButton.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 (‘&’), PySide.QtGui.QAbstractButton automatically creates a shortcut key. For example:

button = QPushButton(QObject.tr("Ro&ck && Roll"), self)

The Alt+C shortcut is assigned to the button, i.e., when the user presses Alt+C the button will call PySide.QtGui.QAbstractButton.animateClick() . See the QShortcut documentation for details (to display an actual ampersand, use ‘&&’).

You can also set a custom shortcut key using the PySide.QtGui.QAbstractButton.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 ( PySide.QtGui.QPushButton , PySide.QtGui.QToolButton , PySide.QtGui.QCheckBox , and PySide.QtGui.QRadioButton ) can display both PySide.QtGui.QAbstractButton.text() and icons .

A button can be made the default button in a dialog are provided by QPushButton.setDefault() and QPushButton.setAutoDefault() .

PySide.QtGui.QAbstractButton provides most of the states used for buttons:

The difference between PySide.QtGui.QAbstractButton.isDown() and PySide.QtGui.QAbstractButton.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 ( PySide.QtGui.QAbstractButton.isChecked() and PySide.QtGui.QAbstractButton.isDown() are both false).

PySide.QtGui.QAbstractButton provides four signals:

To subclass PySide.QtGui.QAbstractButton , you must reimplement at least PySide.QtGui.QAbstractButton.paintEvent() to draw the button’s outline and its text or pixmap. It is generally advisable to reimplement PySide.QtGui.QWidget.sizeHint() as well, and sometimes PySide.QtGui.QAbstractButton.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 PySide.QtGui.QAbstractButton.checkStateSet() and PySide.QtGui.QAbstractButton.nextCheckState() .

class PySide.QtGui.QAbstractButton([parent=None])
Parameters:parentPySide.QtGui.QWidget

Constructs an abstract button with a parent .

PySide.QtGui.QAbstractButton.animateClick([msec=100])
Parameters:msecPySide.QtCore.int

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.

PySide.QtGui.QAbstractButton.autoExclusive()
Return type:PySide.QtCore.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.

PySide.QtGui.QAbstractButton.autoExclusive() is off by default, except for radio buttons.

PySide.QtGui.QAbstractButton.autoRepeat()
Return type:PySide.QtCore.bool

This property holds whether PySide.QtGui.QAbstractButton.autoRepeat() is enabled.

If PySide.QtGui.QAbstractButton.autoRepeat() is enabled, then the PySide.QtGui.QAbstractButton.pressed() , PySide.QtGui.QAbstractButton.released() , and PySide.QtGui.QAbstractButton.clicked() signals are emitted at regular intervals when the button is down. PySide.QtGui.QAbstractButton.autoRepeat() is off by default. The initial delay and the repetition interval are defined in milliseconds by PySide.QtGui.QAbstractButton.autoRepeatDelay() and PySide.QtGui.QAbstractButton.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 PySide.QtGui.QAbstractButton.pressed() , PySide.QtGui.QAbstractButton.released() , and PySide.QtGui.QAbstractButton.clicked() signals will be emitted like in the normal case.

PySide.QtGui.QAbstractButton.autoRepeatDelay()
Return type:PySide.QtCore.int

This property holds the initial delay of auto-repetition.

If PySide.QtGui.QAbstractButton.autoRepeat() is enabled, then PySide.QtGui.QAbstractButton.autoRepeatDelay() defines the initial delay in milliseconds before auto-repetition kicks in.

PySide.QtGui.QAbstractButton.autoRepeatInterval()
Return type:PySide.QtCore.int

This property holds the interval of auto-repetition.

If PySide.QtGui.QAbstractButton.autoRepeat() is enabled, then PySide.QtGui.QAbstractButton.autoRepeatInterval() defines the length of the auto-repetition interval in millisecons.

PySide.QtGui.QAbstractButton.checkStateSet()

This virtual handler is called when PySide.QtGui.QAbstractButton.setChecked() was called, unless it was called from within PySide.QtGui.QAbstractButton.nextCheckState() . It allows subclasses to reset their intermediate button states.

PySide.QtGui.QAbstractButton.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.

PySide.QtGui.QAbstractButton.clicked([checked=false])
Parameters:checkedPySide.QtCore.bool
PySide.QtGui.QAbstractButton.group()
Return type:PySide.QtGui.QButtonGroup

Returns the group that this button belongs to.

If the button is not a member of any PySide.QtGui.QButtonGroup , this function returns 0.

PySide.QtGui.QAbstractButton.hitButton(pos)
Parameters:posPySide.QtCore.QPoint
Return type:PySide.QtCore.bool

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.

PySide.QtGui.QAbstractButton.icon()
Return type:PySide.QtGui.QIcon

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 PySide.QtGui.QAbstractButton.iconSize() property.

PySide.QtGui.QAbstractButton.iconSize()
Return type:PySide.QtCore.QSize

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.

PySide.QtGui.QAbstractButton.isCheckable()
Return type:PySide.QtCore.bool

This property holds whether the button is checkable.

By default, the button is not checkable.

See also

checked()

PySide.QtGui.QAbstractButton.isChecked()
Return type:PySide.QtCore.bool

This property holds whether the button is checked.

Only checkable buttons can be checked. By default, the button is unchecked.

See also

checkable()

PySide.QtGui.QAbstractButton.isDown()
Return type:PySide.QtCore.bool

This property holds whether the button is pressed down.

If this property is true, the button is pressed down. The signals PySide.QtGui.QAbstractButton.pressed() and PySide.QtGui.QAbstractButton.clicked() are not emitted if you set this property to true. The default is false.

PySide.QtGui.QAbstractButton.nextCheckState()

This virtual handler is called when a button is clicked. The default implementation calls setChecked(! PySide.QtGui.QAbstractButton.isChecked() ) if the button PySide.QtGui.QAbstractButton.isCheckable() . It allows subclasses to implement intermediate button states.

PySide.QtGui.QAbstractButton.pressed()
PySide.QtGui.QAbstractButton.released()
PySide.QtGui.QAbstractButton.setAutoExclusive(arg__1)
Parameters:arg__1PySide.QtCore.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.

PySide.QtGui.QAbstractButton.autoExclusive() is off by default, except for radio buttons.

PySide.QtGui.QAbstractButton.setAutoRepeat(arg__1)
Parameters:arg__1PySide.QtCore.bool

This property holds whether PySide.QtGui.QAbstractButton.autoRepeat() is enabled.

If PySide.QtGui.QAbstractButton.autoRepeat() is enabled, then the PySide.QtGui.QAbstractButton.pressed() , PySide.QtGui.QAbstractButton.released() , and PySide.QtGui.QAbstractButton.clicked() signals are emitted at regular intervals when the button is down. PySide.QtGui.QAbstractButton.autoRepeat() is off by default. The initial delay and the repetition interval are defined in milliseconds by PySide.QtGui.QAbstractButton.autoRepeatDelay() and PySide.QtGui.QAbstractButton.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 PySide.QtGui.QAbstractButton.pressed() , PySide.QtGui.QAbstractButton.released() , and PySide.QtGui.QAbstractButton.clicked() signals will be emitted like in the normal case.

PySide.QtGui.QAbstractButton.setAutoRepeatDelay(arg__1)
Parameters:arg__1PySide.QtCore.int

This property holds the initial delay of auto-repetition.

If PySide.QtGui.QAbstractButton.autoRepeat() is enabled, then PySide.QtGui.QAbstractButton.autoRepeatDelay() defines the initial delay in milliseconds before auto-repetition kicks in.

PySide.QtGui.QAbstractButton.setAutoRepeatInterval(arg__1)
Parameters:arg__1PySide.QtCore.int

This property holds the interval of auto-repetition.

If PySide.QtGui.QAbstractButton.autoRepeat() is enabled, then PySide.QtGui.QAbstractButton.autoRepeatInterval() defines the length of the auto-repetition interval in millisecons.

PySide.QtGui.QAbstractButton.setCheckable(arg__1)
Parameters:arg__1PySide.QtCore.bool

This property holds whether the button is checkable.

By default, the button is not checkable.

See also

checked()

PySide.QtGui.QAbstractButton.setChecked(arg__1)
Parameters:arg__1PySide.QtCore.bool

This property holds whether the button is checked.

Only checkable buttons can be checked. By default, the button is unchecked.

See also

checkable()

PySide.QtGui.QAbstractButton.setDown(arg__1)
Parameters:arg__1PySide.QtCore.bool

This property holds whether the button is pressed down.

If this property is true, the button is pressed down. The signals PySide.QtGui.QAbstractButton.pressed() and PySide.QtGui.QAbstractButton.clicked() are not emitted if you set this property to true. The default is false.

PySide.QtGui.QAbstractButton.setIcon(icon)
Parameters:iconPySide.QtGui.QIcon

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 PySide.QtGui.QAbstractButton.iconSize() property.

PySide.QtGui.QAbstractButton.setIconSize(size)
Parameters:sizePySide.QtCore.QSize

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.

PySide.QtGui.QAbstractButton.setShortcut(key)
Parameters:keyPySide.QtGui.QKeySequence

This property holds the mnemonic associated with the button.

PySide.QtGui.QAbstractButton.setText(text)
Parameters:text – unicode

This property holds the text shown on the button.

If the button has no text, the PySide.QtGui.QAbstractButton.text() function will return a 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.

PySide.QtGui.QAbstractButton.shortcut()
Return type:PySide.QtGui.QKeySequence

This property holds the mnemonic associated with the button.

PySide.QtGui.QAbstractButton.text()
Return type:unicode

This property holds the text shown on the button.

If the button has no text, the PySide.QtGui.QAbstractButton.text() function will return a 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.

PySide.QtGui.QAbstractButton.toggle()

Toggles the state of a checkable button.

See also

checked()

PySide.QtGui.QAbstractButton.toggled(checked)
Parameters:checkedPySide.QtCore.bool