QAbstractButton Class Reference
[QtGui module]
该QAbstractButton类是按钮控件的抽象基类,提供了常见的按键功能。More…
继承QWidget。
通过继承QCheckBox,QPushButton,QRadioButton和QToolButton。
Methods
__init__ (self, QWidget parent = None)
animateClick (self, int msecs = 100)
bool autoExclusive (self)
bool autoRepeat (self)
int autoRepeatDelay (self)
int autoRepeatInterval (self)
changeEvent (self, QEvent e)
checkStateSet (self)
click (self)
bool event (self, QEvent e)
focusInEvent (self, QFocusEvent e)
focusOutEvent (self, QFocusEvent e)
QButtonGroup group (self)
bool hitButton (self, QPoint pos)
QIcon icon (self)
QSize iconSize (self)
bool isCheckable (self)
bool isChecked (self)
bool isDown (self)
keyPressEvent (self, QKeyEvent e)
keyReleaseEvent (self, QKeyEvent e)
mouseMoveEvent (self, QMouseEvent e)
mousePressEvent (self, QMouseEvent e)
mouseReleaseEvent (self, QMouseEvent e)
nextCheckState (self)
paintEvent (self, QPaintEvent e)
setAutoExclusive (self, bool)
setAutoRepeat (self, bool)
setAutoRepeatDelay (self, int)
setAutoRepeatInterval (self, int)
setCheckable (self, bool)
setChecked (self, bool)
setDown (self, bool)
setIcon (self, QIcon icon)
setIconSize (self, QSize size)
setShortcut (self, QKeySequence key)
setText (self, QString text)
QKeySequence shortcut (self)
QString text (self)
timerEvent (self, QTimerEvent e)
toggle (self)
Qt Signals
void clicked (bool = 0)
void pressed ()
void released ()
void toggled (bool)
Detailed Description
该QAbstractButton类是按钮控件的抽象基类,提供了常见的按键功能。
这个类实现了一个abstract按钮。这个类处理用户动作的子类,并指定该按钮的绘制方式。
QAbstractButton提供了两个按键和可复(切换)按钮的支持。辨认的按钮在实施QRadioButton和QCheckBox类。按钮是在实施QPushButton和QToolButton类,这些还提供切换行为,如果需要的话。
任何按钮可以显示一个包含标籤文本和图标。setText( )设置文本;setIcon()设置的图标。如果被禁用的按钮,其标籤更改为给按钮“已禁用”的外观。
如果按钮是一个按钮的文本包含一个连字号( ‘&’ )的字符串, QAbstractButton会自动创建一个快捷键。例如:
[QPushButton]($docs-qpushbutton.html) *button = new [QPushButton]($docs-qpushbutton.html)(tr("Ro&ck && Roll"), this);
该Alt+C快捷方式被分配给该按钮时,即,当用户按下Alt+C该按钮将调用animateClick( ) 。请参阅QShortcut有关详细信息的文档(显示的实际符号,使用“\u0026\u0026” ) 。
您还可以使用设置自定义快捷键setShortcut()函数。这主要是针对那些没有任何文字按钮非常有用,因为它们没有自动的快捷方式。
button->setIcon([QIcon](qicon.html)(":/../img/print.png"));
button->setShortcut(tr("Alt+F7"));
所有Qt提供的按钮(QPushButton,QToolButton,QCheckBox和QRadioButton)可以同时显示text和icons。
A键可在对话框中的默认按钮是由提供QPushButton.setDefault()和QPushButton.setAutoDefault( ) 。
QAbstractButton提供了最常用的按钮的状态:
- 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 QAbstractButton accepts mouse and context menu events when disabled.
- setAutoRepeat() sets whether the button will auto-repeat if the user holds it down. autoRepeatDelay and autoRepeatInterval define how auto-repetition is done.
- setCheckable() sets whether the button is a toggle button or not.
之间的差isDown()和isChecked()如下。当用户点击切换按钮来检查它,按钮是第一pressed然后释放到checked状态。当用户再次单击它(取消选中它) ,按钮首先移动到pressed状态,然后到unchecked状态(isChecked()和isDown( )都是假的) 。
QAbstractButton提供四个信号:
- pressed( )当按下鼠标左键,当鼠标指针在按钮内发出。
- released( )当释放鼠标左键发射。
- clicked()时,当第一次按下,然后释放按钮,当快捷键被键入时,或者当发射click()或animateClick()被调用。
- toggled( )被发射时的切换按钮的状态发生改变。
子类QAbstractButton ,你必须重新实现至少paintEvent( )来绘制按钮的轮廓和它的文本或像素图。通常建议重新实现sizeHint( )为好,有时hitButton( ) (判断按下一个按钮是否在按钮内) 。对于有两个以上的国家(如三态按钮)按钮,您也必须重新实现checkStateSet()和nextCheckState( ) 。
Method Documentation
QAbstractButton.__init__ (self, QWidget parent = None)
该parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。
构造一个抽象的按钮与parent。
QAbstractButton.animateClick (self, int msecs = 100)
这种方法也是一个Qt槽与C + +的签名void animateClick(int = 100)
。
执行一个动画点击:按钮被按下马上,并释放msec毫秒后(默认为100毫秒) 。
再次调用此功能的按钮被释放之前将复位释放定时器。
与点击相关的所有信号都发出适当。
这个函数不执行任何操作,如果该按钮是disabled.
See also click( ) 。
bool QAbstractButton.autoExclusive (self)
bool QAbstractButton.autoRepeat (self)
int QAbstractButton.autoRepeatDelay (self)
int QAbstractButton.autoRepeatInterval (self)
QAbstractButton.changeEvent (self, QEvent e)
从重新实现QWidget.changeEvent( ) 。
QAbstractButton.checkStateSet (self)
这种虚拟处理器被调用时setChecked( )被调用,除非它是从内部调用nextCheckState( ) 。它允许子类重新设置他们的中间按钮状态。
See also nextCheckState( ) 。
QAbstractButton.click (self)
这种方法也是一个Qt槽与C + +的签名void click()
。
进行点击。
所有与点击相关的一般信号被发射(如适用) 。如果按钮是可复,按钮的状态翻转。
这个函数不执行任何操作,如果该按钮是disabled.
See also animateClick( ) 。
bool QAbstractButton.event (self, QEvent e)
从重新实现QObject.event( ) 。
QAbstractButton.focusInEvent (self, QFocusEvent e)
从重新实现QWidget.focusInEvent( ) 。
QAbstractButton.focusOutEvent (self, QFocusEvent e)
从重新实现QWidget.focusOutEvent( ) 。
QButtonGroup QAbstractButton.group (self)
[
返回此按钮所属的组。
]($docs-qbuttongroup.html)
如果按钮没有任何一个成员QButtonGroup,这个函数返回0 。
See also QButtonGroup。
bool QAbstractButton.hitButton (self, QPoint pos)
返回True如果pos是可点击的按钮矩形内,否则返回False 。
默认情况下,可点击区域是整个窗口部件。子类可以重新实现此功能,以提供不同形状和尺寸的可点击区域的支持。
QIcon QAbstractButton.icon (self)
QSize QAbstractButton.iconSize (self)
[
bool QAbstractButton.isCheckable (self)
bool QAbstractButton.isChecked (self)
bool QAbstractButton.isDown (self)
QAbstractButton.keyPressEvent (self, QKeyEvent e)
]($docs-qsize.html)
从重新实现QWidget.keyPressEvent( ) 。
QAbstractButton.keyReleaseEvent (self, QKeyEvent e)
从重新实现QWidget.keyReleaseEvent( ) 。
QAbstractButton.mouseMoveEvent (self, QMouseEvent e)
从重新实现QWidget.mouseMoveEvent( ) 。
QAbstractButton.mousePressEvent (self, QMouseEvent e)
从重新实现QWidget.mousePressEvent( ) 。
QAbstractButton.mouseReleaseEvent (self, QMouseEvent e)
从重新实现QWidget.mouseReleaseEvent( ) 。
QAbstractButton.nextCheckState (self)
一个按钮被点击时,这个虚拟处理器被调用。默认实现调用setChecked ( !isChecked()) ,如果按钮isCheckable( ) 。它可以让子类实现中间按钮状态。
See also checkStateSet( ) 。
QAbstractButton.paintEvent (self, QPaintEvent e)
这种方法是抽象的,应在任何子类中重新实现。
从重新实现QWidget.paintEvent( ) 。
QAbstractButton.setAutoExclusive (self, bool)
QAbstractButton.setAutoRepeat (self, bool)
QAbstractButton.setAutoRepeatDelay (self, int)
QAbstractButton.setAutoRepeatInterval (self, int)
QAbstractButton.setCheckable (self, bool)
QAbstractButton.setChecked (self, bool)
这种方法也是一个Qt槽与C + +的签名void setChecked(bool)
。
QAbstractButton.setDown (self, bool)
QAbstractButton.setIcon (self, QIcon icon)
QAbstractButton.setIconSize (self, QSize size)
这种方法也是一个Qt槽与C + +的签名void setIconSize(const QSize&)
。
QAbstractButton.setShortcut (self, QKeySequence key)
QAbstractButton.setText (self, QString text)
QKeySequence QAbstractButton.shortcut (self)
[
QString QAbstractButton.text (self)
QAbstractButton.timerEvent (self, QTimerEvent e)
]($docs-qkeysequence.html)
QAbstractButton.toggle (self)
这种方法也是一个Qt槽与C + +的签名void toggle()
。
切换可检查的按钮的状态。
See also checked。
Qt Signal Documentation
void clicked (bool = 0)
这是该信号的默认超载。
当按钮被激活(即按下然后释放当鼠标光标在按钮内) ,当快捷键键入,或者当这个信号被发射click()或animateClick()被调用。值得注意的是,该信号是not如果你调用发出setDown( )setChecked()或toggle( ) 。
如果按钮是可复,checked如果是按钮被选中真的,还是假的,如果按钮处于未选中状态。
See also pressed( )released()和toggled( ) 。
void pressed ()
这是该信号的默认超载。
当按钮被按下时,这个信号被发射。
See also released()和clicked( ) 。
void released ()
这是该信号的默认超载。
当按钮被释放这个信号被发射。
See also pressed( )clicked()和toggled( ) 。
void toggled (bool)
这是该信号的默认超载。
这个信号被发射时可检查的按钮改变其状态。checked如果是按钮被选中真的,还是假的,如果按钮处于未选中状态。
这可能是一个用户操作的结果,click()槽的激活,或因为setChecked( )被调用。
在专属按钮组按钮的状态更新这个信号被发射之前。这意味着,槽可以在任一“关”的信号,或通过其状态已经改变的组中的按钮发出的“接通”信号采取行动。
例如,一个插槽,反应由新检出的按钮,但是它忽略来自已被取消选中使用下面的图案可以被实现按钮信号发射的信号:
void MyWidget.reactToToggle(bool checked)
{
if (checked) {
// Examine the new button states.
...
}
}
可以使用创建按钮组QButtonGroup类,并更新到按钮状态与监视QButtonGroup.buttonClicked()信号。