The QComboBox 小部件是組閤按鈕和彈齣列錶。 更多...
| 頭: | #include <QComboBox> |
| qmake: | QT += widgets |
| 繼承: | QWidget |
| 繼承者: | QFontComboBox |
| enum | InsertPolicy { NoInsert, InsertAtTop, InsertAtCurrent, InsertAtBottom, ..., InsertAlphabetically } |
| enum | SizeAdjustPolicy { AdjustToContents, AdjustToContentsOnFirstShow, AdjustToMinimumContentsLength, AdjustToMinimumContentsLengthWithIcon } |
|
|
| QComboBox (QWidget * parent = nullptr) | |
| virtual | ~QComboBox () |
| void | addItem (const QString & text , const QVariant & userData = QVariant()) |
| void | addItem (const QIcon & icon , const QString & text , const QVariant & userData = QVariant()) |
| void | addItems (const QStringList & texts ) |
| QCompleter * | completer () const |
| int | count () const |
| QVariant | currentData (int role = Qt::UserRole) const |
| int | currentIndex () const |
| QString | currentText () const |
| bool | duplicatesEnabled () const |
| int | findData (const QVariant & data , int role = Qt::UserRole, Qt::MatchFlags flags = static_cast<Qt::MatchFlags>(Qt::MatchExactly|Qt::MatchCaseSensitive)) const |
| int | findText (const QString & text , Qt::MatchFlags flags = ...) const |
| bool | hasFrame () const |
| virtual void | hidePopup () |
| QSize | iconSize () const |
| void | insertItem (int index , const QString & text , const QVariant & userData = QVariant()) |
| void | insertItem (int index , const QIcon & icon , const QString & text , const QVariant & userData = QVariant()) |
| void | insertItems (int index , const QStringList & list ) |
| QComboBox::InsertPolicy | insertPolicy () const |
| void | insertSeparator (int index ) |
| bool | isEditable () const |
| QVariant | itemData (int index , int role = Qt::UserRole) const |
| QAbstractItemDelegate * | itemDelegate () const |
| QIcon | itemIcon (int index ) const |
| QString | itemText (int index ) const |
| QLineEdit * | lineEdit () const |
| int | maxCount () const |
| int | maxVisibleItems () const |
| int | minimumContentsLength () const |
| QAbstractItemModel * | model () const |
| int | modelColumn () const |
| void | removeItem (int index ) |
| QModelIndex | rootModelIndex () const |
| void | setCompleter (QCompleter * completer ) |
| void | setDuplicatesEnabled (bool enable ) |
| void | setEditable (bool editable ) |
| void | setFrame ( bool ) |
| void | setIconSize (const QSize & size ) |
| void | setInsertPolicy (QComboBox::InsertPolicy policy ) |
| void | setItemData (int index , const QVariant & value , int role = Qt::UserRole) |
| void | setItemDelegate (QAbstractItemDelegate * delegate ) |
| void | setItemIcon (int index , const QIcon & icon ) |
| void | setItemText (int index , const QString & text ) |
| void | setLineEdit (QLineEdit * edit ) |
| void | setMaxCount (int max ) |
| void | setMaxVisibleItems (int maxItems ) |
| void | setMinimumContentsLength (int characters ) |
| void | setModel (QAbstractItemModel * model ) |
| void | setModelColumn (int visibleColumn ) |
| void | setRootModelIndex (const QModelIndex & index ) |
| void | setSizeAdjustPolicy (QComboBox::SizeAdjustPolicy policy ) |
| void | setValidator (const QValidator * validator ) |
| void | setView (QAbstractItemView * itemView ) |
| virtual void | showPopup () |
| QComboBox::SizeAdjustPolicy | sizeAdjustPolicy () const |
| const QValidator * | validator () const |
| QAbstractItemView * | view () const |
| virtual bool | event (QEvent * event ) override |
| virtual QVariant | inputMethodQuery (Qt::InputMethodQuery query ) const override |
| virtual QSize | minimumSizeHint () const override |
| virtual QSize | sizeHint () const override |
| void | clear () |
| void | clearEditText () |
| void | setCurrentIndex (int index ) |
| void | setCurrentText (const QString & text ) |
| void | setEditText (const QString & text ) |
| void | activated (int index ) |
| void | activated (const QString & text ) |
| void | currentIndexChanged (int index ) |
| void | currentIndexChanged (const QString & text ) |
| void | currentTextChanged (const QString & text ) |
| void | editTextChanged (const QString & text ) |
| void | highlighted (int index ) |
| void | highlighted (const QString & text ) |
| const QMetaObject | staticMetaObject |
| void | initStyleOption (QStyleOptionComboBox * option ) const |
| virtual void | changeEvent (QEvent * e ) override |
| virtual void | contextMenuEvent (QContextMenuEvent * e ) override |
| virtual void | focusInEvent (QFocusEvent * e ) override |
| virtual void | focusOutEvent (QFocusEvent * e ) override |
| virtual void | hideEvent (QHideEvent * e ) override |
| virtual void | inputMethodEvent (QInputMethodEvent * e ) override |
| virtual void | keyPressEvent (QKeyEvent * e ) override |
| virtual void | keyReleaseEvent (QKeyEvent * e ) override |
| virtual void | mousePressEvent (QMouseEvent * e ) override |
| virtual void | mouseReleaseEvent (QMouseEvent * e ) override |
| virtual void | paintEvent (QPaintEvent * e ) override |
| virtual void | resizeEvent (QResizeEvent * e ) override |
| virtual void | showEvent (QShowEvent * e ) override |
| virtual void | wheelEvent (QWheelEvent * e ) override |
The QComboBox 小部件是組閤按鈕和彈齣列錶。
A QComboBox 以占用最少屏幕空間數量的方式,嚮用戶提供呈現選項列錶的手段。
組閤框是顯示當前項的選擇 Widget,且可以彈齣可選擇項的列錶。組閤框可能是可編輯的,使用戶能夠修改每列錶項。
組閤框可以包含像素圖及字符串; insertItem () 和 setItemText () 函數適閤被重載。對於可編輯組閤框,函數 clearEditText () 的提供,不改變組閤框內容清零顯示字符串。
有 2 個信號被發射,若當前組閤框項改變,
currentIndexChanged
() 和
activated
().
currentIndexChanged
() 始終被發射,不管改變是通過編程方式完成,還是通過用戶交互完成,而
activated
() 纔發射,當通過用戶交互導緻改變時。
highlighted
() 信號發射,當用戶高亮組閤框彈齣列錶項時。所有 3 信號均有 2 個版本,一個帶有
QString
自變量和一個帶有
int
自變量。若用戶選擇 (或高亮) 像素圖,僅
int
信號被發射。每當可編輯組閤框文本改變時
editTextChanged
() 信號發射。
當用戶在可編輯組閤框中錄入新字符串時,Widget 可能 (或可能不) 插入它,且還可以把它插入在多個位置。默認策略是 InsertAtBottom 但可以改變這使用 setInsertPolicy ().
它是可能的,將輸入約束到可編輯組閤框使用 QValidator ;見 setValidator ()。默認情況下,接受任何輸入。
可以使用插入函數填充組閤框, insertItem () 和 insertItems () 例如。可以改變項采用 setItemText ()。可以移除項采用 removeItem () 和可以移除所有項采用 clear ()。返迴當前項文本通過 currentText (),和采用 text() 返迴編號項文本。可以設置當前項采用 setCurrentIndex ()。組閤框項數的返迴是通過 count ();可以設置最大項數采用 setMaxCount ()。可以允許編輯使用 setEditable ()。對於可編輯組閤框,可以設置自動補全使用 setCompleter () 和設置用戶是否可以重復添加是采用 setDuplicatesEnabled ().
QComboBox 使用 模型/視圖框架 為其彈齣列錶並存儲其項。默認情況下 QStandardItemModel 存儲項和 QListView 子類顯示彈齣列錶。可以直接訪問模型和視圖 (采用 model () 和 view ()),但 QComboBox 還提供用來設置和獲取項數據的函數 (如 setItemData () 和 itemText ())。還可以設置新的模型和視圖 (采用 setModel () 和 setView ())。對於組閤框標簽文本和圖標,模型數據擁有 Qt::DisplayRole and Qt::DecorationRole 在使用。注意:不可以更改 SelectionMode 的 view (),如通過使用 setSelectionMode() .
另請參閱 QLineEdit , QSpinBox , QRadioButton , QButtonGroup ,和 GUI 設計手冊:組閤框、下拉列錶框 .
此枚舉指定什麼是 QComboBox 應該做的,當用戶鍵入新字符串時。
| 常量 | 值 | 描述 |
|---|---|---|
QComboBox::NoInsert
|
0
|
字符串不會插入組閤框。 |
QComboBox::InsertAtTop
|
1
|
字符串將插入作為第一組閤框項。 |
QComboBox::InsertAtCurrent
|
2
|
當前項將 replaced 通過字符串。 |
QComboBox::InsertAtBottom
|
3
|
將字符串插入在組閤框最後項之後。 |
QComboBox::InsertAfterCurrent
|
4
|
將字符串插入在組閤框當前項之後。 |
QComboBox::InsertBeforeCurrent
|
5
|
將字符串插入在組閤框當前項之前。 |
QComboBox::InsertAlphabetically
|
6
|
按字母次序將字符串插入組閤框。 |
此枚舉指定大小提示如何 QComboBox 調節當添加新內容或改變內容時。
| 常量 | 值 | 描述 |
|---|---|---|
QComboBox::AdjustToContents
|
0
|
組閤框始終根據內容調節 |
QComboBox::AdjustToContentsOnFirstShow
|
1
|
組閤框將調節到其首次展示內容。 |
QComboBox::AdjustToMinimumContentsLength
|
2
|
使用 AdjustToContents 或 AdjustToContentsOnFirstShow 代替。 |
QComboBox::AdjustToMinimumContentsLengthWithIcon
|
3
|
組閤框將調節到 minimumContentsLength 加圖標空間。齣於性能原因,在大型模型中使用此策略。 |
此特性保持組閤框中的項數
默認情況下,對於空組閤框,此特性擁有 0 值。
訪問函數:
| int | count () const |
此特性保持當前項的數據
默認情況下,對於空組閤框或未設置當前項的組閤框,此特性包含無效 QVariant .
該特性在 Qt 5.2 引入。
訪問函數:
| QVariant | currentData (int role = Qt::UserRole) const |
此特性保持組閤框當前項的索引。
當前索引會改變,在插入或移除項時。
默認情況下,對於空組閤框或未設置當前項的組閤框,此特性擁有 -1 值。
訪問函數:
| int | currentIndex () const |
| void | setCurrentIndex (int index ) |
通知程序信號:
| void | currentIndexChanged (int index ) |
| void | currentIndexChanged (const QString & text ) |
此特性保持當前文本
若組閤框是可編輯的,當前文本是由行編輯顯示的值。否則,它是當前項的值,或空字符串若組閤框為空或未設置當前項。
setter setCurrentText() 隻需調用 setEditText () 若組閤框是可編輯的。否則,若列錶中有匹配文本, currentIndex 被設為相應索引。
訪問函數:
| QString | currentText () const |
| void | setCurrentText (const QString & text ) |
通知程序信號:
| void | currentTextChanged (const QString & text ) |
另請參閱 editable and setEditText ().
此特性保持用戶是否可以把重復項錄入組閤框
注意:以編程方式把重復項插入組閤框始終是可能的。
默認情況下,此特性為
false
(不允許重復)。
訪問函數:
| bool | duplicatesEnabled () const |
| void | setDuplicatesEnabled (bool enable ) |
此特性保持組閤框是否可以被用戶所編輯
默認情況下,此特性為
false
。編輯的效果取決於插入策略。
注意: 當禁用 editable 狀態,驗證器和補全器被移除。
訪問函數:
| bool | isEditable () const |
| void | setEditable (bool editable ) |
另請參閱 InsertPolicy .
此特性保持組閤框是否采用框架繪製自身
若啓用 (認默) 組閤框將自身繪製在框架內,否則組閤框將繪製自身沒有任何框架。
訪問函數:
| bool | hasFrame () const |
| void | setFrame ( bool ) |
此特性保持組閤框中展示圖標的尺寸。
除非明確設置,否則返迴當前風格的默認值。此尺寸是圖標可以擁有的最大尺寸。不會按比例放大較小尺寸圖標。
訪問函數:
| QSize | iconSize () const |
| void | setIconSize (const QSize & size ) |
此特性保持用於確定用戶插入項應齣現在組閤框哪裏的策略
默認值為 InsertAtBottom ,指示新項將齣現在項列錶底部。
訪問函數:
| QComboBox::InsertPolicy | insertPolicy () const |
| void | setInsertPolicy (QComboBox::InsertPolicy policy ) |
另請參閱 InsertPolicy .
此特性保持組閤框允許的最大項數
注意: 若將最大數設為小於當前組閤框項數量,額外項將被截取。若有為組閤框設置外部模型,這也適用。
默認情況下,此特性值派生自最高可用有符號整數 (通常為 2147483647)。
訪問函數:
| int | maxCount () const |
| void | setMaxCount (int max ) |
此特性保持組閤框在屏幕上的最大允許尺寸,以項數度量
默認情況下,此特性擁有 10 值。
注意: 不可編輯組閤框忽略此特性當樣式返迴 true 時對於 QStyle::SH_ComboBox_Popup (譬如:Mac 樣式或 Gtk+ 樣式)。
訪問函數:
| int | maxVisibleItems () const |
| void | setMaxVisibleItems (int maxItems ) |
此特性保持組閤框應擬閤的最小字符數。
默認值為 0。
若把此特性設為正值, minimumSizeHint () 和 sizeHint () 把它考慮在內。
訪問函數:
| int | minimumContentsLength () const |
| void | setMinimumContentsLength (int characters ) |
另請參閱 sizeAdjustPolicy .
此特性保持可見模型列。
若在填充組閤框之前設置,彈齣視圖將不受影響且會展示第一列 (使用此屬性的默認值)。
默認情況下,此特性擁有 0 值。
訪問函數:
| int | modelColumn () const |
| void | setModelColumn (int visibleColumn ) |
此特性保持描述組閤框尺寸如何變化的策略,當內容更改時
默認值為 AdjustToContentsOnFirstShow .
訪問函數:
| QComboBox::SizeAdjustPolicy | sizeAdjustPolicy () const |
| void | setSizeAdjustPolicy (QComboBox::SizeAdjustPolicy policy ) |
另請參閱 SizeAdjustPolicy .
構造組閤框采用給定 parent ,使用默認模型 QStandardItemModel .
[虛擬]
QComboBox::
~QComboBox
()
銷毀組閤框。
[signal]
void
QComboBox::
activated
(
int
index
)
此信號被發射當用戶選取組閤框項時。項的 index 被傳遞。注意:此信號被發送,甚至在選取不改變時。若需要知道選取實際何時改變,使用信號 currentIndexChanged ().
注意: 信號 activated 在此類中被重載。通過使用函數指針句法連接到此信號,Qt 提供用於獲得如此範例展示的函數指針的方便幫助程序:
connect(comboBox, QOverload<int>::of(&QComboBox::activated), [=](int index){ /* ... */ });
[signal]
void
QComboBox::
activated
(const
QString
&
text
)
此信號被發射當用戶選取組閤框項時。項的 text 被傳遞。注意:此信號被發送,甚至在選取不改變時。若需要知道選取實際何時改變,使用信號 currentIndexChanged ().
注意: 信號 activated 在此類中被重載。通過使用函數指針句法連接到此信號,Qt 提供用於獲得如此範例展示的函數指針的方便幫助程序:
connect(comboBox, QOverload<const QString &>::of(&QComboBox::activated), [=](const QString &text){ /* ... */ });
把項添加到組閤框,采用給定 text ,和包含指定 userData (存儲在 Qt::UserRole )。項會被追加到現有項列錶。
把項添加到組閤框,采用給定 icon and text ,和包含指定 userData (存儲在 Qt::UserRole )。項會被追加到現有項列錶。
添加每字符串按給定 texts 到組閤框。每項被依次追加到現有項列錶。
[override virtual protected]
void
QComboBox::
changeEvent
(
QEvent
*
e
)
重實現自 QWidget::changeEvent ().
[slot]
void
QComboBox::
clear
()
清零組閤框,移除所有項。
注意:若組閤框有設置外部模型,此模型仍會被清零 (當調用此函數時)。
[slot]
void
QComboBox::
clearEditText
()
清零用於組閤框編輯的行編輯內容。
返迴被用於自動補全組閤框文本輸入的補全器。
該函數在 Qt 4.2 引入。
另請參閱 setCompleter () 和 editable .
[override virtual protected]
void
QComboBox::
contextMenuEvent
(
QContextMenuEvent
*
e
)
重實現自 QWidget::contextMenuEvent ().
[signal]
void
QComboBox::
currentIndexChanged
(
int
index
)
此信號被發送每當 currentIndex 在組閤框透過用戶交互或編程方式改變。項的 index 被傳遞或 -1,若組閤框變為空或 currentIndex 被重置。
注意: 信號 currentIndexChanged 在此類中被重載。通過使用函數指針句法連接到此信號,Qt 提供用於獲得如此範例展示的函數指針的方便幫助程序:
connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){ /* ... */ });
該函數在 Qt 4.1 引入。
注意: 通知程序信號對於特性 currentIndex .
[signal]
void
QComboBox::
currentIndexChanged
(const
QString
&
text
)
此信號被發送每當 currentIndex 在組閤框透過用戶交互或編程方式改變。項的 text 被傳遞。
注意: 信號 currentIndexChanged 在此類中被重載。通過使用函數指針句法連接到此信號,Qt 提供用於獲得如此範例展示的函數指針的方便幫助程序:
connect(comboBox, QOverload<const QString &>::of(&QComboBox::currentIndexChanged), [=](const QString &text){ /* ... */ });
該函數在 Qt 4.1 引入。
注意: 通知程序信號對於特性 currentIndex .
[signal]
void
QComboBox::
currentTextChanged
(const
QString
&
text
)
此信號被發送每當 currentText 改變。新值的傳遞是按 text .
該函數在 Qt 5.0 引入。
注意: 通知程序信號對於特性 currentText .
[signal]
void
QComboBox::
editTextChanged
(const
QString
&
text
)
此信號被發射當組閤框行編輯 Widget 文本改變時。指定新文本通過 text .
[override virtual]
bool
QComboBox::
event
(
QEvent
*
event
)
重實現自 QWidget::event ().
返迴索引當項包含給定 data 為給定 role ;否則返迴 -1。
The flags 指定如何搜索組閤框項。
返迴索引當項包含給定 text ;否則返迴 -1。
The flags 指定如何搜索組閤框項。
[override virtual protected]
void
QComboBox::
focusInEvent
(
QFocusEvent
*
e
)
重實現自 QWidget::focusInEvent ().
[override virtual protected]
void
QComboBox::
focusOutEvent
(
QFocusEvent
*
e
)
重實現自 QWidget::focusOutEvent ().
[override virtual protected]
void
QComboBox::
hideEvent
(
QHideEvent
*
e
)
重實現自 QWidget::hideEvent ().
[虛擬]
void
QComboBox::
hidePopup
()
隱藏組閤框項列錶若它目前可見並重置內部狀態,以便若自定義彈齣窗口展示在重實現 showPopup (),那麼還需要重實現 hidePopup() 函數以隱藏自定義彈齣窗口,和調用基類實現以重置內部狀態每當自定義彈齣 Widget 被隱藏時。
另請參閱 showPopup ().
[signal]
void
QComboBox::
highlighted
(
int
index
)
此信號被發送,當用戶突顯組閤框彈齣列錶項。項的 index 被傳遞。
注意: 信號 highlighted 在此類中被重載。通過使用函數指針句法連接到此信號,Qt 提供用於獲得如此範例展示的函數指針的方便幫助程序:
connect(comboBox, QOverload<int>::of(&QComboBox::highlighted), [=](int index){ /* ... */ });
[signal]
void
QComboBox::
highlighted
(const
QString
&
text
)
此信號被發送,當用戶突顯組閤框彈齣列錶項。項的 text 被傳遞。
注意: 信號 highlighted 在此類中被重載。通過使用函數指針句法連接到此信號,Qt 提供用於獲得如此範例展示的函數指針的方便幫助程序:
connect(comboBox, QOverload<const QString &>::of(&QComboBox::highlighted), [=](const QString &text){ /* ... */ });
[protected]
void
QComboBox::
initStyleOption
(
QStyleOptionComboBox
*
option
) const
初始化 option 采用值來自此 QComboBox 。此方法對子類是有用的,當需要 QStyleOptionComboBox ,但不希望自己填充所有信息。
另請參閱 QStyleOption::initFrom ().
[override virtual protected]
void
QComboBox::
inputMethodEvent
(
QInputMethodEvent
*
e
)
重實現自 QWidget::inputMethodEvent ().
[override virtual]
QVariant
QComboBox::
inputMethodQuery
(
Qt::InputMethodQuery
query
) const
重實現自 QWidget::inputMethodQuery ().
插入 text and userData (存儲在 Qt::UserRole ) 進組閤框按給定 index .
若索引 >= 項總數,將新項追加到現有項列錶。若索引為 0 (或為負),將新項前置到現有項列錶。
另請參閱 insertItems ().
插入 icon , text and userData (存儲在 Qt::UserRole ) 進組閤框按給定 index .
若索引 >= 項總數,將新項追加到現有項列錶。若索引為 0 (或為負),將新項前置到現有項列錶。
另請參閱 insertItems ().
插入字符串從 list 到組閤框作為單獨項,起始於 index 指定。
若索引 >= 項總數,將新項追加到現有項列錶。若索引為 0 (或為負),將新項前置到現有項列錶。
另請參閱 insertItem ().
將分隔符項插入組閤框在給定 index .
若索引 >= 項總數,將新項追加到現有項列錶。若索引為 0 (或為負),將新項前置到現有項列錶。
該函數在 Qt 4.4 引入。
另請參閱 insertItem ().
返迴數據為給定 role 以給定 index in the combobox, or QVariant::Invalid if there is no data for this role.
另請參閱 setItemData ().
返迴由彈齣列錶視圖使用的項委托。
另請參閱 setItemDelegate ().
返迴圖標為給定 index 在組閤框。
另請參閱 setItemIcon ().
返迴文本為給定 index 在組閤框。
另請參閱 setItemText ().
[override virtual protected]
void
QComboBox::
keyPressEvent
(
QKeyEvent
*
e
)
重實現自 QWidget::keyPressEvent ().
[override virtual protected]
void
QComboBox::
keyReleaseEvent
(
QKeyEvent
*
e
)
重實現自 QWidget::keyReleaseEvent ().
Returns the line edit used to edit items in the combobox, or 0 if there is no line edit.
僅可編輯組閤框擁有行編輯。
另請參閱 setLineEdit ().
[override virtual]
QSize
QComboBox::
minimumSizeHint
() const
重實現自 QWidget::minimumSizeHint ().
返迴由組閤框使用的模型。
另請參閱 setModel ().
[override virtual protected]
void
QComboBox::
mousePressEvent
(
QMouseEvent
*
e
)
重實現自 QWidget::mousePressEvent ().
[override virtual protected]
void
QComboBox::
mouseReleaseEvent
(
QMouseEvent
*
e
)
重實現自 QWidget::mouseReleaseEvent ().
[override virtual protected]
void
QComboBox::
paintEvent
(
QPaintEvent
*
e
)
重實現自 QWidget::paintEvent ().
移除項位於給定 index 從組閤框。這將更新當前索引,若索引被移除。
此函數什麼都不做,若 index 超齣範圍。
[override virtual protected]
void
QComboBox::
resizeEvent
(
QResizeEvent
*
e
)
重實現自 QWidget::resizeEvent ().
返迴組閤框項的根模型項索引。
另請參閱 setRootModelIndex ().
設置 completer 以使用而不是當前補全器。若 completer is 0, auto completion is disabled.
默認情況下,對於可編輯組閤框, QCompleter 自動創建不區分大小寫的內聯補全。
注意:
補全器被移除,當
editable
特性變為
false
.
該函數在 Qt 4.2 引入。
另請參閱 completer ().
[slot]
void
QComboBox::
setEditText
(const
QString
&
text
)
設置 text 在組閤框的文本編輯。
設置數據 role 為項在給定 index 在組閤框到指定 value .
另請參閱 itemData ().
設置項 delegate 為彈齣列錶視圖。組閤框擁有委托的所有權。
警告: 不應該在組閤框、Widget 映射器或視圖之間共享同一委托實例。這樣做會導緻不正確或不直觀的編輯行為,由於連接到給定委托的每個視圖可能接收 closeEditor() 信號,且試圖訪問、修改或關閉已關閉的編輯器。
另請參閱 itemDelegate ().
設置 icon 為項在給定 index 在組閤框。
另請參閱 itemIcon ().
設置 text 為項在給定 index 在組閤框。
另請參閱 itemText ().
設置行 edit 以代替使用當前行編輯 Widget。
組閤框擁有行編輯的所有權。
另請參閱 lineEdit ().
將模型設為 model . model must not be 0. If you want to clear the contents of a model, call clear ().
設置根模型項 index 為組閤框項。
另請參閱 rootModelIndex ().
設置 validator 以代替當前使用的驗證器。
注意:
驗證器被移除,當
editable
特性變為
false
.
另請參閱 validator ().
將組閤框彈齣所用視圖設為給定 itemView 。組閤框擁有視圖的所有權。
注意:若想要使用方便視圖 (像 QListWidget , QTableWidget or QTreeWidget ),確保調用 setModel () 在組閤框采用方便 Widget 模型,在調用此函數之前。
另請參閱 view ().
[override virtual protected]
void
QComboBox::
showEvent
(
QShowEvent
*
e
)
重實現自 QWidget::showEvent ().
[虛擬]
void
QComboBox::
showPopup
()
Displays the list of items in the combobox. If the list is empty then the no items will be shown.
若重實現此函數以展示自定義彈齣,確保調用 hidePopup () 去重置內部狀態。
另請參閱 hidePopup ().
[override virtual]
QSize
QComboBox::
sizeHint
() const
重實現自 QWidget::sizeHint ().
此實現緩存大小提示以避免重置大小,當內容動態改變時。要使緩存值無效,改變 sizeAdjustPolicy .
返迴用於約束組閤框文本輸入的驗證器。
另請參閱 setValidator () 和 editable .
返迴用於組閤框彈齣的列錶視圖。
另請參閱 setView ().
[override virtual protected]
void
QComboBox::
wheelEvent
(
QWheelEvent
*
e
)
重實現自 QWidget::wheelEvent ().