The Q3ComboBox 小部件是組閤按鈕和彈齣列錶。 更多...
| 頭: | #include <Q3ComboBox> |
| Since: | Qt 4.1 |
| 繼承: | QWidget |
| enum | Policy { NoInsertion, AtTop, AtCurrent, AtBottom, AfterCurrent, BeforeCurrent } |
|
|
| Q3ComboBox (QWidget * parent = 0, const char * name = 0) | |
| Q3ComboBox (bool rw , QWidget * parent = 0, const char * name = 0) | |
| ~Q3ComboBox () | |
| bool | autoCompletion () const |
| bool | autoResize () const |
| void | changeItem (const QString & t , int index ) |
| void | changeItem (const QPixmap & im , int index ) |
| void | changeItem (const QPixmap & im , const QString & t , int index ) |
| int | count () const |
| int | currentItem () const |
| QString | currentText () const |
| bool | duplicatesEnabled () const |
| bool | editable () const |
| void | hide () |
| void | insertItem (const QString & t , int index = -1) |
| void | insertItem (const QPixmap & pixmap , int index = -1) |
| void | insertItem (const QPixmap & pixmap , const QString & text , int index = -1) |
| void | insertStrList (const char ** strings , int numStrings = -1, int index = -1) |
| void | insertStrList (const Q3StrList & list , int index = -1) |
| void | insertStrList (const Q3StrList * list , int index = -1) |
| void | insertStringList (const QStringList & list , int index = -1) |
| Policy | insertionPolicy () const |
| QLineEdit * | lineEdit () const |
| Q3ListBox * | listBox () const |
| int | maxCount () const |
| const QPixmap * | pixmap (int index ) const |
| virtual void | popup () |
| void | removeItem (int index ) |
| virtual void | setAutoCompletion (bool) |
| virtual void | setAutoResize (bool enable ) |
| virtual void | setCurrentItem (int index ) |
| virtual void | setCurrentText (const QString &) |
| void | setDuplicatesEnabled (bool enable ) |
| void | setEditable (bool) |
| void | setEnabled (bool enable ) |
| void | setFont (const QFont & font ) |
| virtual void | setInsertionPolicy (Policy policy ) |
| virtual void | setLineEdit (QLineEdit * edit ) |
| virtual void | setListBox (Q3ListBox * newListBox ) |
| virtual void | setMaxCount (int) |
| void | setPalette (const QPalette & palette ) |
| virtual void | setSizeLimit (int) |
| virtual void | setValidator (const QValidator * v ) |
| int | sizeLimit () const |
| QString | text (int index ) const |
| const QValidator * | validator () const |
| virtual QSize | sizeHint () const |
| void | clear () |
| void | clearEdit () |
| void | clearValidator () |
| virtual void | setEditText (const QString & newText ) |
| void | activated (int index ) |
| void | activated (const QString & string ) |
| void | highlighted (int index ) |
| void | highlighted (const QString & string ) |
| void | textChanged (const QString & string ) |
| void | updateMask () |
| virtual void | focusInEvent (QFocusEvent * e ) |
| virtual void | focusOutEvent (QFocusEvent * e ) |
| virtual void | keyPressEvent (QKeyEvent * e ) |
| virtual void | mouseDoubleClickEvent (QMouseEvent * e ) |
| virtual void | mouseMoveEvent (QMouseEvent *) |
| virtual void | mousePressEvent (QMouseEvent * e ) |
| virtual void | mouseReleaseEvent (QMouseEvent *) |
| virtual void | paintEvent (QPaintEvent *) |
| virtual void | resizeEvent (QResizeEvent * e ) |
| virtual void | wheelEvent (QWheelEvent * e ) |
The Q3ComboBox 小部件是組閤按鈕和彈齣列錶。
A combobox is a selection widget which displays the current item and can pop up a list of items. A combobox may be editable in which case the user can enter arbitrary strings.
Comboboxes provide a means of showing the user's current choice out of a list of options in a way that takes up the minimum amount of screen space.
Q3ComboBox supports three different display styles: Aqua/Motif 1.x, Motif 2.0 and Windows. In Motif 1.x, a combobox was called XmOptionMenu. In Motif 2.0, OSF introduced an improved combobox and named that XmComboBox. Q3ComboBox provides both.
Q3ComboBox provides two different constructors. The simplest constructor creates an "old-style" combobox in Motif (or Aqua) style:
Q3ComboBox *c = new Q3ComboBox(this, tr("read-only combobox"));
The other constructor creates a new-style combobox in Motif style, and can create both read-only and editable comboboxes:
Q3ComboBox *c1 = new Q3ComboBox(false, this, tr("read-only combobox")); Q3ComboBox *c2 = new Q3ComboBox(true, this, tr("editable combobox"));
New-style comboboxes use a list box in both Motif and Windows styles, and both the content size and the on-screen size of the list box can be limited with sizeLimit () 和 setMaxCount () respectively. Old-style comboboxes use a popup in Aqua and Motif style, and that popup will happily grow larger than the desktop if you put enough data into it.
The two constructors create identical-looking comboboxes in Windows style.
組閤框可以包含像素圖及字符串; insertItem () 和 changeItem () 函數適閤被重載。對於可編輯組閤框,函數 clearEdit () 的提供,不改變組閤框內容清零顯示字符串。
A combobox emits two signals,
activated
() 和
highlighted
(), when a new item has been activated (selected) or highlighted (made current). Both signals exist in two versions, one with a
QString
自變量和一個帶有
int
argument. If the user highlights or activates a pixmap, only the
int
信號被發射。每當可編輯組閤框文本改變時
textChanged
() 信號發射。
When the user enters a new string in an editable combobox, the widget may or may not insert it, and it can insert it in several locations. The default policy is is
AtBottom
但可以改變這使用
setInsertionPolicy
().
它是可能的,將輸入約束到可編輯組閤框使用 QValidator ;見 setValidator ()。默認情況下,接受任何輸入。
If the combobox is not editable then it has a default
focusPolicy
() of
TabFocus
, i.e. it will not grab focus if clicked. This differs from both Windows and Motif. If the combobox is editable then it has a default
focusPolicy
() of
StrongFocus
, i.e. it will grab focus if clicked.
可以使用插入函數填充組閤框, insertStringList () 和 insertItem () 例如。可以改變項采用 changeItem ()。可以移除項采用 removeItem () 和可以移除所有項采用 clear ()。返迴當前項文本通過 currentText (), and the text of a numbered item is returned with text (). The current item can be set with setCurrentItem () 或 setCurrentText ()。組閤框項數的返迴是通過 count ();可以設置最大項數采用 setMaxCount ()。可以允許編輯使用 setEditable ()。對於可編輯組閤框,可以設置自動補全使用 setAutoCompletion () 和設置用戶是否可以重復添加是采用 setDuplicatesEnabled ().
Depending on the style, Q3ComboBox will use a list box or a popup menu to display the list of items. See setListBox () 瞭解更多信息。
{GUI Design Handbook}{GUI Design Handbook: Combo Box, Drop-Down List Box}
另請參閱 QComboBox , QLineEdit ,和 QSpinBox .
此枚舉指定什麼是 Q3ComboBox 應該做的,當用戶鍵入新字符串時。
| 常量 | 值 | 描述 |
|---|---|---|
Q3ComboBox::NoInsertion
|
0
|
the string will not be inserted into the combobox. |
Q3ComboBox::AtTop
|
1
|
insert the string as the first item in the combobox. |
Q3ComboBox::AtCurrent
|
2
|
replace the previously selected item with the string the user has entered. |
Q3ComboBox::AtBottom
|
3
|
insert the string as the last item in the combobox. |
Q3ComboBox::AfterCurrent
|
4
|
insert the string after the previously selected item. |
Q3ComboBox::BeforeCurrent
|
5
|
insert the string before the previously selected item. |
activated () is always emitted when the string is entered.
If inserting the new string would cause the combobox to breach its content size limit, the item at the other end of the list is deleted. The definition of "other end" is implementation-dependent.
This property holds whether auto-completion is enabled.
This property can only be set for editable comboboxes, for non-editable comboboxes it has no effect. It is false by default.
訪問函數:
| bool | autoCompletion () const |
| virtual void | setAutoCompletion (bool) |
此特性保持組閤框中的項數。
訪問函數:
| int | count () const |
此特性保持組閤框當前項的索引。
注意, activated () 和 highlighted () signals are only emitted when the user changes the current item, not when it is changed programmatically.
訪問函數:
| int | currentItem () const |
| virtual void | setCurrentItem (int index ) |
This property holds the text of the combobox's current item.
訪問函數:
| QString | currentText () const |
| virtual void | setCurrentText (const QString &) |
This property holds whether duplicates are allowed.
If the combobox is editable and the user enters some text in the combobox's lineedit and presses Enter (and the
insertionPolicy
() is not
NoInsertion
), then what happens is this:
This property only affects user-interaction. You can use insertItem () to insert duplicates if you wish regardless of this setting.
訪問函數:
| bool | duplicatesEnabled () const |
| void | setDuplicatesEnabled (bool enable ) |
This property holds whether the combobox is editable.
This property's default is false. Note that the combobox will be cleared if this property is set to true for a 1.x Motif style combobox. To avoid this, use setEditable() before inserting any items. Also note that the 1.x version of Motif didn't have any editable comboboxes, so the combobox will change its appearance to a 2.0 style Motif combobox is it is set to be editable.
訪問函數:
| bool | editable () const |
| void | setEditable (bool) |
This property holds the position of the items inserted by the user.
The default insertion policy is
AtBottom
。見
Policy
.
訪問函數:
| Policy | insertionPolicy () const |
| virtual void | setInsertionPolicy (Policy policy ) |
此特性保持組閤框最大允許項數。
訪問函數:
| int | maxCount () const |
| virtual void | setMaxCount (int) |
This property holds the maximum on-screen size of the combobox.
This property is ignored for both Motif 1.x style and non-editable comboboxes in Mac style. The default limit is ten lines. If the number of items in the combobox is or grows larger than lines, a scroll bar is added.
訪問函數:
| int | sizeLimit () const |
| virtual void | setSizeLimit (int) |
Constructs a combobox widget with parent parent called name .
This constructor creates a popup list if the program uses Motif (or Aqua) look and feel; this is compatible with Motif 1.x and Aqua.
Note: If you use this constructor to create your Q3ComboBox , then the pixmap () function will always return 0. To workaround this, use the other constructor.
Constructs a combobox with a maximum size and either Motif 2.0 or Windows look and feel.
The input field can be edited if rw is true, otherwise the user may only choose one of the items in the combobox.
The parent and name arguments are passed on to the QWidget 構造函數。
銷毀組閤框。
[signal]
void
Q3ComboBox::
activated
(
int
index
)
This signal is emitted when a new item has been activated (selected). The index is the position of the item in the combobox.
This signal is not emitted if the item is changed programmatically, e.g. using setCurrentItem ().
注意: 信號 activated 在此類中是重載。要使用函數指針句法連接到此信號,必須在靜態鑄造中指定信號類型,如此範例所示:
connect(3ComboBox, static_cast<void(Q3ComboBox::*)(int)>(&Q3ComboBox::activated), [=](int index){ /* ... */ });
[signal]
void
Q3ComboBox::
activated
(const
QString
&
string
)
這是重載函數。
This signal is emitted when a new item has been activated (selected). string is the selected string.
You can also use the activated(int) signal, but be aware that its argument is meaningful only for selected strings, not for user entered strings.
注意: 信號 activated 在此類中是重載。要使用函數指針句法連接到此信號,必須在靜態鑄造中指定信號類型,如此範例所示:
connect(3ComboBox, static_cast<void(Q3ComboBox::*)(const QString &)>(&Q3ComboBox::activated), [=](const QString &string){ /* ... */ });
Returns true if auto-resize is enabled; otherwise returns false.
另請參閱 setAutoResize () 和 autoResize .
Replaces the item at position index with the text t .
這是重載函數。
Replaces the item at position index with the pixmap im , unless the combobox is editable.
另請參閱 insertItem ().
這是重載函數。
Replaces the item at position index with the pixmap im 和文本 t .
另請參閱 insertItem ().
[slot]
void
Q3ComboBox::
clear
()
Removes all combobox items.
[slot]
void
Q3ComboBox::
clearEdit
()
Clears the line edit without changing the combobox's contents. Does nothing if the combobox isn't editable.
This is particularly useful when using a combobox as a line edit with history. For example you can connect the combobox's activated () signal to clearEdit() in order to present the user with a new, empty line as soon as Enter is pressed.
另請參閱 setEditText ().
[slot]
void
Q3ComboBox::
clearValidator
()
This slot is equivalent to setValidator ( 0 ).
[virtual protected]
void
Q3ComboBox::
focusInEvent
(
QFocusEvent
*
e
)
重實現自 QWidget::focusInEvent ().
[virtual protected]
void
Q3ComboBox::
focusOutEvent
(
QFocusEvent
*
e
)
重實現自 QWidget::focusOutEvent ().
Hides the combobox.
另請參閱 QWidget::hide ().
[signal]
void
Q3ComboBox::
highlighted
(
int
index
)
This signal is emitted when a new item has been set to be the current item. The index is the position of the item in the combobox.
This signal is not emitted if the item is changed programmatically, e.g. using setCurrentItem ().
注意: 信號 highlighted 在此類中是重載。要使用函數指針句法連接到此信號,必須在靜態鑄造中指定信號類型,如此範例所示:
connect(3ComboBox, static_cast<void(Q3ComboBox::*)(int)>(&Q3ComboBox::highlighted), [=](int index){ /* ... */ });
[signal]
void
Q3ComboBox::
highlighted
(const
QString
&
string
)
這是重載函數。
This signal is emitted when a new item has been set to be the current item. string is the item's text.
You can also use the highlighted(int) signal.
注意: 信號 highlighted 在此類中是重載。要使用函數指針句法連接到此信號,必須在靜態鑄造中指定信號類型,如此範例所示:
connect(3ComboBox, static_cast<void(Q3ComboBox::*)(const QString &)>(&Q3ComboBox::highlighted), [=](const QString &string){ /* ... */ });
Inserts a text item with text t , at position index . The item will be appended if index 為負。
這是重載函數。
插入 pixmap item at position index . The item will be appended if index 為負。
這是重載函數。
插入 pixmap item with additional text text 在位置 index . The item will be appended if index 為負。
Inserts the array of char * strings 在位置 index 在組閤框。
The numStrings argument is the number of strings. If numStrings is -1 (default), the strings array must be terminated with 0.
範例:
static const char* items[] = { "red", "green", "blue", 0 }; combo->insertStrList( items );
另請參閱 insertStringList ().
這是重載函數。
插入 list of strings at position index 在組閤框。
This is only for compatibility since it does not support Unicode strings. See insertStringList ().
這是重載函數。
插入 list of strings at position index 在組閤框。
This is only for compatibility since it does not support Unicode strings. See insertStringList ().
插入 list of strings at position index 在組閤框。
[virtual protected]
void
Q3ComboBox::
keyPressEvent
(
QKeyEvent
*
e
)
重實現自 QWidget::keyPressEvent ().
Returns the line edit, or 0 if there is no line edit.
Only editable listboxes have a line editor.
另請參閱 setLineEdit ().
Returns the current list box, or 0 if there is no list box. ( Q3ComboBox can use QPopupMenu 而不是 QListBox .) Provided to match setListBox ().
另請參閱 setListBox ().
[virtual protected]
void
Q3ComboBox::
mouseDoubleClickEvent
(
QMouseEvent
*
e
)
重實現自 QWidget::mouseDoubleClickEvent ().
[virtual protected]
void
Q3ComboBox::
mouseMoveEvent
(
QMouseEvent
*)
重實現自 QWidget::mouseMoveEvent ().
[virtual protected]
void
Q3ComboBox::
mousePressEvent
(
QMouseEvent
*
e
)
重實現自 QWidget::mousePressEvent ().
[virtual protected]
void
Q3ComboBox::
mouseReleaseEvent
(
QMouseEvent
*)
重實現自 QWidget::mouseReleaseEvent ().
[virtual protected]
void
Q3ComboBox::
paintEvent
(
QPaintEvent
*)
重實現自 QWidget::paintEvent ().
Returns the pixmap item at position index , or 0 if the item is not a pixmap.
[虛擬]
void
Q3ComboBox::
popup
()
Pops up the combobox popup list.
If the list is empty, no items appear.
Removes the item at position index .
[virtual protected]
void
Q3ComboBox::
resizeEvent
(
QResizeEvent
*
e
)
重實現自 QWidget::resizeEvent ().
[虛擬]
void
Q3ComboBox::
setAutoResize
(
bool
enable
)
若 enable is true, enable auto-resize; disable it otherwise.
另請參閱 autoResize .
[virtual slot]
void
Q3ComboBox::
setEditText
(const
QString
&
newText
)
Sets the text in the line edit to newText without changing the combobox's contents. Does nothing if the combobox isn't editable.
This is useful e.g. for providing a good starting point for the user's editing and entering the change in the combobox only when the user presses Enter.
另請參閱 clearEdit () 和 insertItem ().
Enables the combobox if enable 為 true;否則禁用它。
另請參閱 QWidget::enabled .
Sets the font for both the combobox button and the combobox popup list to font .
[虛擬]
void
Q3ComboBox::
setLineEdit
(
QLineEdit
*
edit
)
Sets the line edit to use edit instead of the current line edit.
另請參閱 lineEdit ().
[虛擬]
void
Q3ComboBox::
setListBox
(
Q3ListBox
*
newListBox
)
Sets the combobox to use newListBox instead of the current list box or popup. As a side effect, it clears the combobox of its current contents.
警告: Q3ComboBox assumes that newListBox->text(n) returns non-null for 0 <= n < newListbox-> count (). This assumption is necessary because of the line edit in Q3ComboBox .
另請參閱 listBox ().
Sets the palette for both the combobox button and the combobox popup list to palette .
[虛擬]
void
Q3ComboBox::
setValidator
(const
QValidator
*
v
)
Applies the validator v to the combobox so that only text which is valid according to v is accepted.
This function does nothing if the combobox is not editable.
另請參閱 validator (), clearValidator (),和 QValidator .
[虛擬]
QSize
Q3ComboBox::
sizeHint
() const
重實現自 QWidget::sizeHint ().
This implementation caches the size hint to avoid resizing when the contents change dynamically. To invalidate the cached value call setFont ().
Returns the text item at position index ,或 QString::null if the item is not a string.
另請參閱 currentText ().
[signal]
void
Q3ComboBox::
textChanged
(const
QString
&
string
)
This signal is used for editable comboboxes. It is emitted whenever the contents of the text entry field changes. string contains the new text.
[protected]
void
Q3ComboBox::
updateMask
()
Updates the widget mask.
另請參閱 QWidget::setMask ().
Returns the validator which constrains editing for this combobox if there is one; otherwise returns 0.
另請參閱 setValidator (), clearValidator (),和 QValidator .
[virtual protected]
void
Q3ComboBox::
wheelEvent
(
QWheelEvent
*
e
)
重實現自 QWidget::wheelEvent ().