The QAbstractButton 類是按鈕 Widget 抽象基類,為按鈕提供公共功能。 更多...
| 頭: | #include <QAbstractButton> |
| 繼承: | QWidget |
| 繼承者: | Q3Button , QCheckBox , QPushButton , QRadioButton ,和 QToolButton |
|
| QAbstractButton (QWidget * parent = 0) | |
| ~QAbstractButton () | |
| bool | autoExclusive () const |
| bool | autoRepeat () const |
| int | autoRepeatDelay () const |
| int | autoRepeatInterval () const |
| QButtonGroup * | group () const |
| QIcon | icon () const |
| QSize | iconSize () const |
| bool | isCheckable () const |
| bool | isChecked () const |
| bool | isDown () const |
| void | setAutoExclusive (bool) |
| void | setAutoRepeat (bool) |
| void | setAutoRepeatDelay (int) |
| void | setAutoRepeatInterval (int) |
| void | setCheckable (bool) |
| void | setDown (bool) |
| void | setIcon (const QIcon & icon ) |
| void | setShortcut (const QKeySequence & key ) |
| void | setText (const QString & text ) |
| QKeySequence | shortcut () const |
| QString | text () const |
| void | animateClick (int msec = 100) |
| void | click () |
| void | setChecked (bool) |
| void | setIconSize (const QSize & size ) |
| void | toggle () |
| void | clicked (bool checked = false) |
| void | pressed () |
| void | released () |
| void | toggled (bool checked ) |
| virtual void | checkStateSet () |
| virtual bool | hitButton (const QPoint & pos ) const |
| virtual void | nextCheckState () |
| virtual void | changeEvent (QEvent * e ) |
| virtual bool | event (QEvent * e ) |
| virtual void | focusInEvent (QFocusEvent * e ) |
| virtual void | focusOutEvent (QFocusEvent * e ) |
| virtual void | keyPressEvent (QKeyEvent * e ) |
| virtual void | keyReleaseEvent (QKeyEvent * e ) |
| virtual void | mouseMoveEvent (QMouseEvent * e ) |
| virtual void | mousePressEvent (QMouseEvent * e ) |
| virtual void | mouseReleaseEvent (QMouseEvent * e ) |
| virtual void | paintEvent (QPaintEvent * e ) = 0 |
| virtual void | timerEvent (QTimerEvent * e ) |
The QAbstractButton 類是按鈕 Widget 抽象基類,為按鈕提供公共功能。
此類實現 abstract 按鈕。此類的子類處理用戶動作,並指定如何繪製按鈕。
QAbstractButton 為按鈕和可復選 (觸發) 按鈕提供支持。可復選按鈕的實現在 QRadioButton and QCheckBox 類。按鈕的實現在 QPushButton and QToolButton 類;這些還提供觸發行為若有要求。
任何按鈕都可以顯示包含文本和圖標的標簽。 setText () 設置文本; setIcon () 設置圖標。若按鈕被禁用,將改變其標簽以賦予按鈕禁用外觀。
若按鈕是具有包含和號 & 字符串的文本按鈕, QAbstractButton 會自動創建快捷鍵。例如:
QPushButton *button = new QPushButton(tr("Ro&ck && Roll"), this);
The Alt+C 快捷方式被賦值給按鈕,即:當用戶按下 Alt+C 按鈕會調用 animateClick ()。見 QShortcut 文檔編製瞭解細節 (要顯示實際和號,使用 &&)。
還可以設置自定義快捷鍵使用 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 ( QPushButton , QToolButton , QCheckBox ,和 QRadioButton ) 均可以顯示 text and icons .
A button can be made the default button in a dialog are provided by QPushButton::setDefault () 和 QPushButton::setAutoDefault ().
QAbstractButton 提供用於按鈕的大多數狀態:
注意: 與其它 Widget 相反,按鈕派生 QAbstractButton accepts mouse and context menu events when disabled.
差異在 isDown () 和 isChecked () 如下所示。當用戶點擊觸發按鈕以復選時,按鈕首先 pressed 然後釋放到 checked 狀態。當用戶再次點擊它 (以取消復選) 時,按鈕先被移到 pressed 狀態,然後到 unchecked 狀態 ( isChecked () 和 isDown () 兩者為 false)。
QAbstractButton 提供 4 個信號:
要子類化 QAbstractButton ,必須至少重實現 paintEvent () 以繪製按鈕輪廓及其文本或像素圖。通常明智的是重實現 sizeHint (),且有時是 hitButton () (以確定按鈕按下是否在按鈕內)。對於具有 2 種以上狀態的按鈕 (像 3 狀態按鈕),還必須重實現 checkStateSet () 和 nextCheckState ().
另請參閱 QButtonGroup .
This property holds whether auto-exclusivity is enabled.
若自動獨占被啓用,屬於同一父級 Widget 的可復選按鈕的行為就像它們屬於同一獨占按鈕組。在獨占按鈕組中,任何時候隻能復選一按鈕;復選另一按鈕,自動取消復選先前復選的按鈕。
特性對屬於按鈕組的按鈕,不起作用。
默認情況下,autoExclusive (自動獨占) 是關閉的,除單選按鈕外。
訪問函數:
| bool | autoExclusive () const |
| void | setAutoExclusive (bool) |
另請參閱 QRadioButton .
This property holds whether autoRepeat is enabled.
若 autoRepeat 被啓用,那麼 pressed (), released (),和 clicked () 信號將按定期間隔發射當按鈕被按下時。autoRepeat 默認情況下是關閉的。初始延遲和重復間隔以毫秒為單位定義通過 autoRepeatDelay and autoRepeatInterval .
注意:若按鈕被快捷鍵按下,那麼自動重復是被係統而不是此類啓用和計時。 pressed (), released (),和 clicked () 信號將像在正常情況下一樣被發射。
訪問函數:
| bool | autoRepeat () const |
| void | setAutoRepeat (bool) |
This property holds the initial delay of auto-repetition.
若 autoRepeat 被啓用,那麼 autoRepeatDelay 定義在自動重復反衝之前的初始延遲 (以毫秒為單位)。
該特性在 Qt 4.2 引入。
訪問函數:
| int | autoRepeatDelay () const |
| void | setAutoRepeatDelay (int) |
另請參閱 autoRepeat and autoRepeatInterval .
This property holds the interval of auto-repetition.
若 autoRepeat 被啓用,autoRepeatInterval 將定義自動重復間隔的長度 (以毫秒為單位)。
該特性在 Qt 4.2 引入。
訪問函數:
| int | autoRepeatInterval () const |
| void | setAutoRepeatInterval (int) |
另請參閱 autoRepeat and autoRepeatDelay .
This property holds whether the button is checkable.
默認情況下,按鈕是不可復選的。
訪問函數:
| bool | isCheckable () const |
| void | setCheckable (bool) |
另請參閱 checked .
This property holds whether the button is checked.
僅可復選按鈕纔可以被復選。默認情況下,按鈕是取消復選的。
訪問函數:
| bool | isChecked () const |
| void | setChecked (bool) |
通知程序信號:
| void | toggled (bool checked ) |
另請參閱 checkable .
This property holds whether the button is pressed down.
If this property is true, the button is pressed down. The signals pressed () 和 clicked () 不發射,若將此特性設為 true。默認為 false。
訪問函數:
| bool | isDown () const |
| void | setDown (bool) |
This property holds the icon shown on the button.
圖標的默認大小由 GUI 樣式定義,但可以調節通過設置 iconSize 特性。
訪問函數:
| QIcon | icon () const |
| void | setIcon (const QIcon & icon ) |
此特性保持用於此按鈕的圖標尺寸。
默認大小由 GUI 樣式定義。這是圖標的最大尺寸。不會按比例放大較小圖標。
訪問函數:
| QSize | iconSize () const |
| void | setIconSize (const QSize & size ) |
This property holds the mnemonic associated with the button.
訪問函數:
| QKeySequence | shortcut () const |
| void | setShortcut (const QKeySequence & key ) |
This property holds the text shown on the button.
If the button has no text, the 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 文檔編製瞭解細節 (要顯示實際和號,使用 &&)。
不存在默認文本。
訪問函數:
| QString | text () const |
| void | setText (const QString & text ) |
構造抽象按鈕采用 parent .
銷毀按鈕。
[slot]
void
QAbstractButton::
animateClick
(
int
msec
= 100)
履行動畫點擊:立即按下按鈕,然後釋放在 msec 毫秒後 (默認為 100 ms)。
Calling this function again before the button was released will reset the release timer.
會酌情發射點擊關聯的所有信號。
此函數什麼都不做若按鈕 disabled.
另請參閱 click ().
[virtual protected]
void
QAbstractButton::
changeEvent
(
QEvent
*
e
)
重實現自 QWidget::changeEvent ().
[virtual protected]
void
QAbstractButton::
checkStateSet
()
此虛擬處理程序被調用當 setChecked () was called, unless it was called from within nextCheckState ()。它允許子類重置它們的中間按鈕狀態。
另請參閱 nextCheckState ().
[slot]
void
QAbstractButton::
click
()
履行點擊。
與點擊關聯的所有尋常信號都會適當發射。若按鈕可復選,觸發按鈕狀態。
此函數什麼都不做若按鈕 disabled.
另請參閱 animateClick ().
[signal]
void
QAbstractButton::
clicked
(
bool
checked
= false)
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 () 或 animateClick () 被調用。顯而易見,此信號 not 被發射若調用 setDown (), setChecked () 或 toggle ().
若按鈕是可復選的, checked 為 true 若按鈕被復選,或 false 若按鈕未被復選。
另請參閱 pressed (), released (),和 toggled ().
[virtual protected]
bool
QAbstractButton::
event
(
QEvent
*
e
)
重實現自 QObject::event ().
[virtual protected]
void
QAbstractButton::
focusInEvent
(
QFocusEvent
*
e
)
重實現自 QWidget::focusInEvent ().
[virtual protected]
void
QAbstractButton::
focusOutEvent
(
QFocusEvent
*
e
)
重實現自 QWidget::focusOutEvent ().
返迴此按鈕所屬的組。
若按鈕不是成員對於任何 QButtonGroup ,此函數返迴 0。
另請參閱 QButtonGroup .
[virtual protected]
bool
QAbstractButton::
hitButton
(const
QPoint
&
pos
) const
返迴 true 若 pos is inside the clickable button rectangle; otherwise returns false.
默認情況下,可點擊區域是整個 Widget。子類可以重實現此函數,以提供不同形狀和大小的可點擊區域支持。
[virtual protected]
void
QAbstractButton::
keyPressEvent
(
QKeyEvent
*
e
)
重實現自 QWidget::keyPressEvent ().
[virtual protected]
void
QAbstractButton::
keyReleaseEvent
(
QKeyEvent
*
e
)
重實現自 QWidget::keyReleaseEvent ().
[virtual protected]
void
QAbstractButton::
mouseMoveEvent
(
QMouseEvent
*
e
)
重實現自 QWidget::mouseMoveEvent ().
[virtual protected]
void
QAbstractButton::
mousePressEvent
(
QMouseEvent
*
e
)
重實現自 QWidget::mousePressEvent ().
[virtual protected]
void
QAbstractButton::
mouseReleaseEvent
(
QMouseEvent
*
e
)
重實現自 QWidget::mouseReleaseEvent ().
[virtual protected]
void
QAbstractButton::
nextCheckState
()
調用此虛擬處理程序,當點擊按鈕時。默認實現調用 setChecked (! isChecked ()) 若按鈕 isCheckable ()。它允許子類實現中間按鈕狀態。
另請參閱 checkStateSet ().
[pure virtual protected]
void
QAbstractButton::
paintEvent
(
QPaintEvent
*
e
)
重實現自 QWidget::paintEvent ().
[signal]
void
QAbstractButton::
pressed
()
此信號發射,當按下按鈕時。
另請參閱 released () 和 clicked ().
[signal]
void
QAbstractButton::
released
()
此信號發射,當釋放按鈕時。
另請參閱 pressed (), clicked (),和 toggled ().
[virtual protected]
void
QAbstractButton::
timerEvent
(
QTimerEvent
*
e
)
重實現自 QObject::timerEvent ().
[slot]
void
QAbstractButton::
toggle
()
切換可復選按鈕的狀態。
另請參閱 checked .