Q3ComboBox Class Reference |
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 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.
This enum specifies what the Q3ComboBox should do when a new string is entered by the user.
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.6-snapshot | |
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