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 ) |
This property holds the maximum number of items allowed in the combobox.
访问函数:
| 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 ().