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  · 

QComboBox Class Reference
[QtGui module]

The QComboBox widget is a combined button and popup list. More...

#include <QComboBox>

Inherits QWidget.

Public Types

  • enum InsertPolicy { NoInsert, InsertAtTop, InsertAtCurrent, InsertAtBottom, InsertAfterCurrent, InsertBeforeCurrent }
  • enum SizeAdjustPolicy { AdjustToContents, AdjustToContentsOnFirstShow, AdjustToMinimumContentsLength }

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

Additional Inherited Members

  • 4 static public members inherited from QWidget
  • 4 static public members inherited from QObject
  • 39 protected functions inherited from QWidget
  • 7 protected functions inherited from QObject
  • 1 protected function inherited from QPaintDevice

Detailed Description

The QComboBox widget is a combined button and popup list.

A QComboBox provides a means of presenting a list of options to the user in a way that takes up the minimum amount of screen space.

A combobox is a selection widget that displays the current item, and can pop up a list of selectable items. A combobox may be editable, allowing the user to modify each item in the list.

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

It is possible to constrain the input to an editable combobox using QValidator; see setValidator(). By default, any input is accepted.

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

Comboboxes in the different built-in styles.

See also QLineEdit, QSpinBox, QRadioButton, QButtonGroup, and GUI Design Handbook: Combo Box, Drop-Down List Box.


Member Type Documentation

enum QComboBox::InsertPolicy

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

ConstantValueDescription
QComboBox::NoInsert0The string will not be inserted into the combobox.
QComboBox::InsertAtTop1The string will be inserted as the first item in the combobox.
QComboBox::InsertAtCurrent2The current item will be replaced by the string.
QComboBox::InsertAtBottom3The string will be inserted after the last item in the combobox.
QComboBox::InsertAfterCurrent4The string is inserted after the current item in the combobox.
QComboBox::InsertBeforeCurrent5The string is inserted before the current item in the combobox.

enum QComboBox::SizeAdjustPolicy

This enum specifies how the size of the QComboBox should adjust when new content is added or content changes.

ConstantValueDescription
QComboBox::AdjustToContents0The combobox will always adjust to the contens
QComboBox::AdjustToContentsOnFirstShow1The combobox will adjust to its contents the first time it is show.
QComboBox::AdjustToMinimumContentsLength2The combobox only adjusts to the minimumContentsLength


Property Documentation

autoCompletion : bool

This property holds whether the combobox provides auto-completion for editable items.

This property was introduced in Qt 4.1.

Access functions:

  • bool autoCompletion () const
  • void setAutoCompletion ( bool enable )

See also editable.

autoCompletionCaseSensitivity : Qt::CaseSensitivity

This property holds the case-sensitive property used in auto-completion.

Access functions:

  • Qt::CaseSensitivity autoCompletionCaseSensitivity () const
  • void setAutoCompletionCaseSensitivity ( Qt::CaseSensitivity sensitivity )

See also autoCompletion.

count : const int

This property holds the number of items in the combobox.

Access functions:

  • int count () const

currentIndex : int

This property holds the index of the current item in the combobox. The index can change when inserting or removing items. Returns -1 if no current item is set or the combobox is empty.

Access functions:

  • int currentIndex () const
  • void setCurrentIndex ( int index )

currentText : const QString

This property holds the text of the current item.

Access functions:

  • QString currentText () const

duplicatesEnabled : bool

This property holds whether the user can enter duplicate items into the combobox.

Note that it is always possible to programatically insert duplicate items into the combobox.

Access functions:

  • bool duplicatesEnabled () const
  • void setDuplicatesEnabled ( bool enable )

editable : bool

This property holds whether the combobox can be edited by the user.

Access functions:

  • bool isEditable () const
  • void setEditable ( bool editable )

frame : bool

This property holds whether the combo box draws itself with a frame.

If enabled (the default) the combo box draws itself inside a frame, otherwise the combo box draws itself without any frame.

Access functions:

  • bool hasFrame () const
  • void setFrame ( bool )

iconSize : QSize

This property holds the size of the icons shown in the combobox.

Unless explicitly set this returns the default value of the current style.

Access functions:

  • QSize iconSize () const
  • void setIconSize ( const QSize & size )

insertPolicy : InsertPolicy

This property holds the policy used to determine where user-inserted items should appear in the combobox.

The default value is AtBottom, indicating that new items will appear at the bottom of the list of items.

Access functions:

  • InsertPolicy insertPolicy () const
  • void setInsertPolicy ( InsertPolicy policy )

See also InsertPolicy.

maxCount : int

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

Note: If you set the maximum number to be less then the current amount of items in the combobox, the extra items will be truncated. This also applies if you have set an external model on the combobox.

Access functions:

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

maxVisibleItems : int

This property holds the maximum allowed size on screen of the combobox.

This property is ignored for non-editable comboboxes in Mac style.

Access functions:

  • int maxVisibleItems () const
  • void setMaxVisibleItems ( int maxItems )

minimumContentsLength : int

This property holds the value describing the minimum number of characters that will fit into the combobox.

This value is ignored if AdjustToMinimumContentsLength is not set. The default value is 0.

Access functions:

  • int minimumContentsLength () const
  • void setMinimumContentsLength ( int characters )

See also sizeAdjustPolicy.

modelColumn : bool

This property holds the column in the model that is visible.

Access functions:

  • int modelColumn () const
  • void setModelColumn ( int visibleColumn )

sizeAdjustPolicy : SizeAdjustPolicy

This property holds the policy describing how the size of the combobox changes when the content changes.

The default value is AdjustToContentsOnFirstShow.

Access functions:

  • SizeAdjustPolicy sizeAdjustPolicy () const
  • void setSizeAdjustPolicy ( SizeAdjustPolicy policy )

See also SizeAdjustPolicy.


Member Function Documentation

QComboBox::QComboBox ( QWidget * parent = 0 )

Constructs a combobox with the given parent, using the default model QStandardItemModel.

QComboBox::~QComboBox ()

Destroys the combobox.

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

This signal is sent when an item in the combobox is activated by the user. The item's index is given.

void QComboBox::activated ( const QString & text )   [signal]

This is an overloaded member function, provided for convenience.

This signal is sent when an item in the combobox is activated by the user. The item's text is given.

void QComboBox::addItem ( const QString & text, const QVariant & userData = QVariant() )

Adds an item to the combobox with the given text, and containing the specified userData. The item is appended to the list of existing items.

void QComboBox::addItem ( const QIcon & icon, const QString & text, const QVariant & userData = QVariant() )

This is an overloaded member function, provided for convenience.

Adds an item to the combobox with the given icon and text, and containing the specified userData. The item is appended to the list of existing items.

void QComboBox::addItems ( const QStringList & texts )

Adds each of the strings in the given texts to the combobox. Each item is appended to the list of existing items in turn.

void QComboBox::clear ()   [slot]

Clears the combobox, removing all items.

Note: If you have set an external model on the combobox this model will still be cleared when calling this function.

void QComboBox::clearEditText ()   [slot]

Clears the contents of the line edit used for editing in the combobox.

void QComboBox::currentIndexChanged ( int index )   [signal]

This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. The item's index is given or -1 if the combobox becomes empty or the currentIndex was reset.

This function was introduced in Qt 4.1.

void QComboBox::currentIndexChanged ( const QString & text )   [signal]

This is an overloaded member function, provided for convenience.

This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. The item's text is given.

This function was introduced in Qt 4.1.

void QComboBox::editTextChanged ( const QString & text )   [signal]

This signal is emitted when the text in the combobox's line edit widget is changed. The new text is specified by text.

int QComboBox::findData ( const QVariant & data, int role = Qt::UserRole, Qt::MatchFlags flags = Qt::MatchExactly | Qt::MatchCaseSensitive ) const

Returns the index of the item containing the given data for the given role; otherwise returns -1.

The flags specify how the items in the combobox are searched.

int QComboBox::findText ( const QString & text, Qt::MatchFlags flags = Qt::MatchExactly | Qt::MatchCaseSensitive ) const

Returns the index of the item containing the given text; otherwise returns -1.

The flags specify how the items in the combobox are searched.

void QComboBox::hidePopup ()   [virtual]

Hides the list of items in the combobox if it is currently visible; otherwise this function does nothing.

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

This signal is sent when an item in the combobox is highlighted by the user. The item's index is given.

void QComboBox::highlighted ( const QString & text )   [signal]

This is an overloaded member function, provided for convenience.

This signal is sent when an item in the combobox is highlighted by the user. The item's text is given.

void QComboBox::insertItem ( int index, const QString & text, const QVariant & userData = QVariant() )

Inserts the text and userData into the combobox at the given index.

void QComboBox::insertItem ( int index, const QIcon & icon, const QString & text, const QVariant & userData = QVariant() )

This is an overloaded member function, provided for convenience.

Inserts the icon, text and userData into the combobox at the given index.

void QComboBox::insertItems ( int index, const QStringList & list )

Inserts the strings from the list into the combobox as separate items, starting at the index specified.

QVariant QComboBox::itemData ( int index, int role = Qt::UserRole ) const

Returns the data for the given role in the given index in the combobox, or QVariant::Invalid if there is no data for this role.

See also setItemData().

QAbstractItemDelegate * QComboBox::itemDelegate () const

Returns the item delegate used by the popup list view.

See also setItemDelegate().

QIcon QComboBox::itemIcon ( int index ) const

Returns the icon for the given index in the combobox.

See also setItemIcon().

QString QComboBox::itemText ( int index ) const

Returns the text for the given index in the combobox.

See also setItemText().

QLineEdit * QComboBox::lineEdit () const

Returns the line edit used to edit items in the combobox, or 0 if there is no line edit.

Only editable combo boxes have a line edit.

See also setLineEdit().

QAbstractItemModel * QComboBox::model () const

Returns the model used by the combobox.

See also setModel().

void QComboBox::removeItem ( int index )

Removes the item at the given index from the combobox. This will update the current index if the index is removed.

QModelIndex QComboBox::rootModelIndex () const

Returns the root model item index for the items in the combobox.

See also setRootModelIndex().

void QComboBox::setEditText ( const QString & text )   [slot]

Sets the text in the combobox's text edit.

void QComboBox::setItemData ( int index, const QVariant & value, int role = Qt::UserRole )

Sets the data role for the item on the given index in the combobox to the specified value.

See also itemData().

void QComboBox::setItemDelegate ( QAbstractItemDelegate * delegate )

Sets the item delegate for the popup list view. The combobox takes ownership of the delegate.

See also itemDelegate().

void QComboBox::setItemIcon ( int index, const QIcon & icon )

Sets the icon for the item on the given index in the combobox.

See also itemIcon().

void QComboBox::setItemText ( int index, const QString & text )

Sets the text for the item on the given index in the combobox.

See also itemText().

void QComboBox::setLineEdit ( QLineEdit * edit )

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

The combo box takes ownership of the line edit.

See also lineEdit().

void QComboBox::setModel ( QAbstractItemModel * model )

Sets the model to be model. model must not be 0. If you want to clear the contents of a model, call clear().

See also model() and clear().

void QComboBox::setRootModelIndex ( const QModelIndex & index )

Sets the root model item index for the items in the combobox.

See also rootModelIndex().

void QComboBox::setValidator ( const QValidator * validator )

Sets the validator to use instead of the current validator.

See also validator().

void QComboBox::setView ( QAbstractItemView * itemView )

Sets the view to be used in the combobox popup to the given itemView. The combobox takes ownership of the view.

Note: If you want to use the convenience views (like QListWidget, QTableWidget or QTreeWidget), make sure to call setModel() on the combobox with the convenience widgets model before calling this function.

See also view().

void QComboBox::showPopup ()   [virtual]

Displays the list of items in the combobox. If the list is empty then the no items will be shown.

const QValidator * QComboBox::validator () const

Returns the validator that is used to constrain text input for the combobox.

See also setValidator() and editable.

QAbstractItemView * QComboBox::view () const

Returns the list view used for the combobox popup.

See also setView().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 12
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Developer Network au hasard

Logo

La création de colonnes dans une ListView en QML

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