内容表

上一话题

QTextEdit.ExtraSelection

下一话题

QAbstractGraphicsShapeItem

QAbstractButton

QAbstractButton class is the abstract base class of button widgets, providing functionality common to buttons. 更多

Inheritance diagram of PySide2.QtWidgets.QAbstractButton

继承者: QCheckBox , QCommandLinkButton , QPushButton , QRadioButton , QToolButton

概要

函数

虚函数

信号

详细描述

此类实现 abstract 按钮。此类的子类处理用户动作,并指定如何绘制按钮。

QAbstractButton provides support for both push buttons and checkable (toggle) buttons. Checkable buttons are implemented in the QRadioButton and QCheckBox 类。按钮的实现在 QPushButton and QToolButton 类;这些还提供触发行为若要求的话。

任何按钮都可以显示包含文本和图标的标签。 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:

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 animateClick() 。见 QShortcut documentation for details. To display an actual ampersand, use ‘&&’.

还可以设置自定义快捷键使用 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"))
											

由 Qt 提供的所有按钮 ( QPushButton , QToolButton , QCheckBox ,和 QRadioButton ) 均可以显示 text and icons .

可以把按钮设为对话框默认按钮通过 setDefault() and setAutoDefault() .

QAbstractButton provides most of the states used for buttons:

差异在 isDown() and isChecked() is as follows. When the user clicks a toggle button to check it, the button is first pressed 然后释放到 checked 状态。当用户再次点击它 (以取消复选) 时,按钮先被移到 pressed 状态,然后到 unchecked 状态 ( isChecked() and isDown() are both false).

QAbstractButton provides four signals:

  1. pressed() is emitted when the left mouse button is pressed while the mouse cursor is inside the button.

  2. released() is emitted when the left mouse button is released.

  3. clicked() is emitted when the button is first pressed and then released, when the shortcut key is typed, or when click() or animateClick() 被调用。

  4. 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() .

另请参阅

QButtonGroup

class QAbstractButton ( [ parent=None ] )
param parent

QWidget

Constructs an abstract button with a parent .

PySide2.QtWidgets.QAbstractButton. animateClick ( [ msec=100 ] )
参数

msec 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 is released resets the release timer.

All signals associated with a click are emitted as appropriate.

This function does nothing if the button is PySide2.QtWidgets.QWidget.setEnabled()

另请参阅

click()

PySide2.QtWidgets.QAbstractButton. autoExclusive ( )
返回类型

bool

PySide2.QtWidgets.QAbstractButton. autoRepeat ( )
返回类型

bool

另请参阅

setAutoRepeat()

PySide2.QtWidgets.QAbstractButton. autoRepeatDelay ( )
返回类型

int

PySide2.QtWidgets.QAbstractButton. autoRepeatInterval ( )
返回类型

int

PySide2.QtWidgets.QAbstractButton. 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.

另请参阅

nextCheckState()

PySide2.QtWidgets.QAbstractButton. 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 PySide2.QtWidgets.QWidget.setEnabled()

另请参阅

animateClick()

PySide2.QtWidgets.QAbstractButton. clicked ( [ checked=false ] )
参数

checked bool

PySide2.QtWidgets.QAbstractButton. group ( )
返回类型

QButtonGroup

Returns the group that this button belongs to.

If the button is not a member of any QButtonGroup ,此函数返回 None .

另请参阅

QButtonGroup

PySide2.QtWidgets.QAbstractButton. hitButton ( pos )
参数

pos QPoint

返回类型

bool

返回 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.

PySide2.QtWidgets.QAbstractButton. icon ( )
返回类型

QIcon

另请参阅

setIcon()

PySide2.QtWidgets.QAbstractButton. iconSize ( )
返回类型

QSize

另请参阅

setIconSize()

PySide2.QtWidgets.QAbstractButton. isCheckable ( )
返回类型

bool

PySide2.QtWidgets.QAbstractButton. isChecked ( )
返回类型

bool

PySide2.QtWidgets.QAbstractButton. isDown ( )
返回类型

bool

PySide2.QtWidgets.QAbstractButton. 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.

另请参阅

checkStateSet()

PySide2.QtWidgets.QAbstractButton. pressed ( )
PySide2.QtWidgets.QAbstractButton. released ( )
PySide2.QtWidgets.QAbstractButton. setAutoExclusive ( arg__1 )
参数

arg__1 bool

另请参阅

autoExclusive()

PySide2.QtWidgets.QAbstractButton. setAutoRepeat ( arg__1 )
参数

arg__1 bool

另请参阅

autoRepeat()

PySide2.QtWidgets.QAbstractButton. setAutoRepeatDelay ( arg__1 )
参数

arg__1 int

另请参阅

autoRepeatDelay()

PySide2.QtWidgets.QAbstractButton. setAutoRepeatInterval ( arg__1 )
参数

arg__1 int

PySide2.QtWidgets.QAbstractButton. setCheckable ( arg__1 )
参数

arg__1 bool

另请参阅

isCheckable()

PySide2.QtWidgets.QAbstractButton. setChecked ( arg__1 )
参数

arg__1 bool

另请参阅

isChecked()

PySide2.QtWidgets.QAbstractButton. setDown ( arg__1 )
参数

arg__1 bool

另请参阅

isDown()

PySide2.QtWidgets.QAbstractButton. setIcon ( icon )
参数

icon QIcon

另请参阅

icon()

PySide2.QtWidgets.QAbstractButton. setIconSize ( size )
参数

size QSize

另请参阅

iconSize()

PySide2.QtWidgets.QAbstractButton. setShortcut ( key )
参数

key QKeySequence

另请参阅

shortcut()

PySide2.QtWidgets.QAbstractButton. setText ( text )
参数

text – unicode

另请参阅

text()

PySide2.QtWidgets.QAbstractButton. shortcut ( )
返回类型

QKeySequence

另请参阅

setShortcut()

PySide2.QtWidgets.QAbstractButton. text ( )
返回类型

unicode

另请参阅

setText()

PySide2.QtWidgets.QAbstractButton. toggle ( )

Toggles the state of a checkable button.

另请参阅

checked

PySide2.QtWidgets.QAbstractButton. toggled ( checked )
参数

checked bool