Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

Q3ComboBox Class Reference
[Qt3Support module]

The 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

  • enum Policy { NoInsertion, AtTop, AtCurrent, AtBottom, AfterCurrent, BeforeCurrent }

Properties

  • 54 properties inherited from QWidget
  • 1 property inherited from QObject

Public Functions

  • 190 public functions inherited from QWidget
  • 28 public functions inherited from QObject
  • 12 public functions inherited from QPaintDevice

Public Slots

  • 17 public slots inherited from QWidget
  • 1 public slot inherited from QObject

Signals

Protected Functions

  • 39 protected functions inherited from QWidget
  • 7 protected functions inherited from QObject
  • 1 protected function inherited from QPaintDevice

Additional Inherited Members

  • 4 static public members inherited from QWidget
  • 4 static public members inherited from QObject

Detailed Description

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.


Member Type Documentation

enum Q3ComboBox::Policy

This enum specifies what the Q3ComboBox should do when a new string is entered by the user.

ConstantValueDescription
Q3ComboBox::NoInsertion0the string will not be inserted into the combobox.
Q3ComboBox::AtTop1insert the string as the first item in the combobox.
Q3ComboBox::AtCurrent2replace the previously selected item with the string the user has entered.
Q3ComboBox::AtBottom3insert the string as the last item in the combobox.
Q3ComboBox::AfterCurrent4insert the string after the previously selected item.
Q3ComboBox::BeforeCurrent5insert 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.


Property Documentation

autoCompletion : bool

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 )

count : const int

This property holds the number of items in the combobox.

Access functions:

  • int count () const

currentItem : int

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 )

currentText : QString

This property holds the text of the combobox's current item.

Access functions:

  • QString currentText () const
  • virtual void setCurrentText ( const QString & )

duplicatesEnabled : bool

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:

  • If the text is not already in the list, the text is inserted.
  • If the text is in the list and this property is true (the default), the text is inserted.
  • If the text is in the list and this property is false, the text is not inserted; instead the item which has matching text becomes the current item.

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 )

editable : bool

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 )

insertionPolicy : Policy

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 )

maxCount : int

This property holds the maximum number of items allowed in the combobox.

Access functions:

  • int maxCount () const
  • virtual void setMaxCount ( int )

sizeLimit : 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 scrollbar is added.

Access functions:

  • int sizeLimit () const
  • virtual void setSizeLimit ( int )

Member Function Documentation

Q3ComboBox::Q3ComboBox ( QWidget * parent = 0, const char * name = 0 )

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.

Q3ComboBox::Q3ComboBox ( bool rw, QWidget * parent = 0, const char * name = 0 )

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.

Q3ComboBox::~Q3ComboBox ()

Destroys the combobox.

void Q3ComboBox::activated ( int index )   [signal]

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().

void Q3ComboBox::activated ( const QString & string )   [signal]

This is an overloaded member function, provided for convenience.

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.

bool Q3ComboBox::autoResize () const

See also setAutoResize().

void Q3ComboBox::changeItem ( const QString & t, int index )

Replaces the item at position index with the text t.

void Q3ComboBox::changeItem ( const QPixmap & im, int index )

This is an overloaded member function, provided for convenience.

Replaces the item at position index with the pixmap im, unless the combobox is editable.

See also insertItem().

void Q3ComboBox::changeItem ( const QPixmap & im, const QString & t, int index )

This is an overloaded member function, provided for convenience.

Replaces the item at position index with the pixmap im and the text t.

See also insertItem().

void Q3ComboBox::clear ()   [slot]

Removes all combobox items.

void Q3ComboBox::clearEdit ()   [slot]

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().

void Q3ComboBox::clearValidator ()   [slot]

This slot is equivalent to setValidator( 0 ).

void Q3ComboBox::hide ()

Hides the combobox.

See also QWidget::hide().

void Q3ComboBox::highlighted ( int index )   [signal]

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().

void Q3ComboBox::highlighted ( const QString & string )   [signal]

This is an overloaded member function, provided for convenience.

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.

void Q3ComboBox::insertItem ( const QString & t, int index = -1 )

Inserts a text item with text t, at position index. The item will be appended if index is negative.

void Q3ComboBox::insertItem ( const QPixmap & pixmap, int index = -1 )

This is an overloaded member function, provided for convenience.

Inserts a pixmap item at position index. The item will be appended if index is negative.

void Q3ComboBox::insertItem ( const QPixmap & pixmap, const QString & text, int index = -1 )

This is an overloaded member function, provided for convenience.

Inserts a pixmap item with additional text text at position index. The item will be appended if index is negative.

void Q3ComboBox::insertStrList ( const char ** strings, int numStrings = -1, int index = -1 )

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().

void Q3ComboBox::insertStrList ( const Q3StrList & list, int index = -1 )

This is an overloaded member function, provided for convenience.

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().

void Q3ComboBox::insertStrList ( const Q3StrList * list, int index = -1 )

This is an overloaded member function, provided for convenience.

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().

void Q3ComboBox::insertStringList ( const QStringList & list, int index = -1 )

Inserts the list of strings at position index in the combobox.

QLineEdit * Q3ComboBox::lineEdit () const

Returns the line edit, or 0 if there is no line edit.

Only editable listboxes have a line editor.

See also setLineEdit().

Q3ListBox * Q3ComboBox::listBox () const

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().

const QPixmap * Q3ComboBox::pixmap ( int index ) const

Returns the pixmap item at position index, or 0 if the item is not a pixmap.

void Q3ComboBox::popup ()   [virtual]

Pops up the combobox popup list.

If the list is empty, no items appear.

void Q3ComboBox::removeItem ( int index )

Removes the item at position index.

void Q3ComboBox::setAutoResize ( bool )   [virtual]

See also autoResize().

void Q3ComboBox::setEditText ( const QString & newText )   [virtual slot]

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().

void Q3ComboBox::setEnabled ( bool enable )

Enables the combobox if enable is true; otherwise disables it.

See also QWidget::enabled.

void Q3ComboBox::setFont ( const QFont & font )

Sets the font for both the combobox button and the combobox popup list to font.

void Q3ComboBox::setLineEdit ( QLineEdit * edit )   [virtual]

Sets the line edit to use edit instead of the current line edit.

See also lineEdit().

void Q3ComboBox::setListBox ( Q3ListBox * newListBox )   [virtual]

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().

void Q3ComboBox::setPalette ( const QPalette & palette )

Sets the palette for both the combobox button and the combobox popup list to palette.

void Q3ComboBox::setValidator ( const QValidator * v )   [virtual]

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.

QString Q3ComboBox::text ( int index ) const

Returns the text item at position index, or QString::null if the item is not a string.

See also currentText().

void Q3ComboBox::textChanged ( const QString & string )   [signal]

This signal is used for editable comboboxes. It is emitted whenever the contents of the text entry field changes. string contains the new text.

void Q3ComboBox::updateMask ()   [protected]

Updates the widget mask.

See also QWidget::setMask().

const QValidator * Q3ComboBox::validator () const

Returns the validator which constrains editing for this combobox if there is one; otherwise returns 0.

See also setValidator(), clearValidator(), and QValidator.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 103
  2. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 53
  3. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 82
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 30
  5. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 11
Page suivante
  1. Linus Torvalds : le "C++ est un langage horrible", en justifiant le choix du C pour le système de gestion de version Git 100
  2. Comment prendre en compte l'utilisateur dans vos applications ? Pour un développeur, « 90 % des utilisateurs sont des idiots » 229
  3. Quel est LE livre que tout développeur doit lire absolument ? Celui qui vous a le plus marqué et inspiré 96
  4. Apple cède et s'engage à payer des droits à Nokia, le conflit des brevets entre les deux firmes s'achève 158
  5. Nokia porte à nouveau plainte contre Apple pour violation de sept nouveaux brevets 158
  6. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 102
  7. Quel est le code dont vous êtes le plus fier ? Pourquoi l'avez-vous écrit ? Et pourquoi vous a-t-il donné autant de satisfaction ? 83
Page suivante

Le Qt Developer Network au hasard

Logo

Combiner licence, à propos et fermer

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

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.1
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 !
 
 
 
 
Partenaires

Hébergement Web