Q3ComboBox Class ReferenceThe Q3ComboBox widget is a combined button and popup list. More... #include <Q3ComboBox> This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code. See Porting to Qt 4 for more information. Inherits: QWidget. This class was introduced in Qt 4.1. Public Types
Properties
Public Functions
Reimplemented Public Functions
Public Slots
Signals
Protected Functions
Reimplemented Protected Functions
Additional Inherited Members
Detailed DescriptionThe Q3ComboBox widget is a combined button and popup list. 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() and 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. Comboboxes can contain pixmaps as well as strings; the insertItem() and changeItem() functions are suitably overloaded. For editable comboboxes, the function clearEdit() is provided, to clear the displayed string without changing the combobox's contents. A combobox emits two signals, activated() and highlighted(), when a new item has been activated (selected) or highlighted (made current). Both signals exist in two versions, one with a QString argument and one with an int argument. If the user highlights or activates a pixmap, only the int signals are emitted. Whenever the text of an editable combobox is changed the textChanged() signal is emitted. 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 but you can change this using setInsertionPolicy(). It is possible to constrain the input to an editable combobox using QValidator; see setValidator(). By default, any input is accepted. 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. A combobox can be populated using the insert functions, insertStringList() and insertItem() for example. Items can be changed with changeItem(). An item can be removed with removeItem() and all items can be removed with clear(). The text of the current item is returned by currentText(), and the text of a numbered item is returned with text(). The current item can be set with setCurrentItem() or setCurrentText(). The number of items in the combobox is returned by count(); the maximum number of items can be set with setMaxCount(). You can allow editing using setEditable(). For editable comboboxes you can set auto-completion using setAutoCompletion() and whether or not the user can add duplicates is set with setDuplicatesEnabled(). Depending on the style, Q3ComboBox will use a list box or a popup menu to display the list of items. See setListBox() for more information. {GUI Design Handbook}{GUI Design Handbook: Combo Box, Drop-Down List Box} See also QComboBox, QLineEdit, and QSpinBox. Member Type Documentation
|
Constant | Value | Description |
---|---|---|
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.
Access functions:
bool | autoCompletion () const |
virtual void | setAutoCompletion ( bool ) |
This property holds the number of items in the combobox.
Access functions:
int | count () const |
This property holds the index of the current item in the combobox.
Note that the activated() and highlighted() signals are only emitted when the user changes the current item, not when it is changed programmatically.
Access functions:
int | currentItem () const |
virtual void | setCurrentItem ( int index ) |
This property holds the text of the combobox's current item.
Access functions:
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.
Access functions:
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.
Access functions:
bool | editable () const |
void | setEditable ( bool ) |
This property holds the position of the items inserted by the user.
The default insertion policy is AtBottom. See Policy.
Access functions:
Policy | insertionPolicy () const |
virtual void | setInsertionPolicy ( Policy policy ) |
This property holds the maximum number of items allowed in the combobox.
Access functions:
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.
Access functions:
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 constructor.
Destroys the combobox.
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().
This is an overloaded function.
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.
Returns true if auto-resize is enabled; otherwise returns false.
See also setAutoResize() and autoResize.
Replaces the item at position index with the text t.
This is an overloaded function.
Replaces the item at position index with the pixmap im, unless the combobox is editable.
See also insertItem().
This is an overloaded function.
Replaces the item at position index with the pixmap im and the text t.
See also insertItem().
Removes all combobox items.
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.
See also setEditText().
This slot is equivalent to setValidator( 0 ).
Reimplemented from QWidget::focusInEvent().
Reimplemented from QWidget::focusOutEvent().
Hides the combobox.
See also QWidget::hide().
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().
This is an overloaded function.
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.
Inserts a text item with text t, at position index. The item will be appended if index is negative.
This is an overloaded function.
Inserts a pixmap item at position index. The item will be appended if index is negative.
This is an overloaded function.
Inserts a pixmap item with additional text text at position index. The item will be appended if index is negative.
Inserts the array of char * strings at position index in the combobox.
The numStrings argument is the number of strings. If numStrings is -1 (default), the strings array must be terminated with 0.
Example:
static const char* items[] = { "red", "green", "blue", 0 }; combo->insertStrList( items );
See also insertStringList().
This is an overloaded function.
Inserts the list of strings at position index in the combobox.
This is only for compatibility since it does not support Unicode strings. See insertStringList().
This is an overloaded function.
Inserts the list of strings at position index in the combobox.
This is only for compatibility since it does not support Unicode strings. See insertStringList().
Inserts the list of strings at position index in the combobox.
Reimplemented from QWidget::keyPressEvent().
Returns the line edit, or 0 if there is no line edit.
Only editable listboxes have a line editor.
See also setLineEdit().
Returns the current list box, or 0 if there is no list box. (Q3ComboBox can use QPopupMenu instead of QListBox.) Provided to match setListBox().
See also setListBox().
Reimplemented from QWidget::mouseDoubleClickEvent().
Reimplemented from QWidget::mouseMoveEvent().
Reimplemented from QWidget::mousePressEvent().
Reimplemented from QWidget::mouseReleaseEvent().
Reimplemented from QWidget::paintEvent().
Returns the pixmap item at position index, or 0 if the item is not a pixmap.
Pops up the combobox popup list.
If the list is empty, no items appear.
Removes the item at position index.
Reimplemented from QWidget::resizeEvent().
If enable is true, enable auto-resize; disable it otherwise.
See also autoResize.
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.
See also clearEdit() and insertItem().
Enables the combobox if enable is true; otherwise disables it.
See also QWidget::enabled.
Sets the font for both the combobox button and the combobox popup list to font.
Sets the line edit to use edit instead of the current line edit.
See also lineEdit().
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.
Warning: 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.
See also listBox().
Sets the palette for both the combobox button and the combobox popup list to palette.
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.
See also validator(), clearValidator(), and QValidator.
Reimplemented from 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, or QString::null if the item is not a string.
See also currentText().
This signal is used for editable comboboxes. It is emitted whenever the contents of the text entry field changes. string contains the new text.
Updates the widget mask.
See also QWidget::setMask().
Returns the validator which constrains editing for this combobox if there is one; otherwise returns 0.
See also setValidator(), clearValidator(), and QValidator.
Reimplemented from QWidget::wheelEvent().
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.8 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com