Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | Properties | Private Member Functions | Related Functions

QComboBox Class Reference

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

Inheritance diagram for QComboBox:
Inheritance graph
Collaboration diagram for QComboBox:
Collaboration graph

List of all members.

Public Types

enum  InsertPolicy {
  NoInsert, InsertAtTop, InsertAtCurrent, InsertAtBottom,
  InsertAfterCurrent, InsertBeforeCurrent, InsertAlphabetically
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
enum  RenderFlag { DrawWindowBackground = 0x1, DrawChildren = 0x2, IgnoreMask = 0x4 }
enum  SizeAdjustPolicy { AdjustToContents, AdjustToContentsOnFirstShow, AdjustToMinimumContentsLength, AdjustToMinimumContentsLengthWithIcon }

Public Slots

void clear ()
void clearEditText ()
bool close ()
void hide ()
void lower ()
void raise ()
void repaint ()
void setCurrentIndex (int index)
void setDisabled (bool)
void setEditText (const QString &text)
void setEnabled (bool)
void setFocus ()
void setHidden (bool hidden)
QT_MOC_COMPAT void setShown (bool shown)
void setStyleSheet (const QString &styleSheet)
virtual void setVisible (bool visible)
void setWindowModified (bool)
void setWindowTitle (const QString &)
void show ()
void showFullScreen ()
void showMaximized ()
void showMinimized ()
void showNormal ()
void update ()


void activated (int index)
void activated (const QString &)
void currentIndexChanged (const QString &)
void currentIndexChanged (int index)
void customContextMenuRequested (const QPoint &pos)
void editTextChanged (const QString &)
void highlighted (int index)
void highlighted (const QString &)

Public Member Functions

bool acceptDrops () const
QString accessibleDescription () const
QString accessibleName () const
QList< QAction * > actions () const
void activateWindow ()
void addAction (QAction *action)
void addActions (QList< QAction * > actions)
void addItem (const QString &text, const QVariant &userData=QVariant())
void addItem (const QIcon &icon, const QString &text, const QVariant &userData=QVariant())
void addItems (const QStringList &texts)
void adjustSize ()
bool autoCompletion () const
Qt::CaseSensitivity autoCompletionCaseSensitivity () const
bool autoFillBackground () const
QPalette::ColorRole backgroundRole () const
QSize baseSize () const
QWidgetchildAt (int x, int y) const
QWidgetchildAt (const QPoint &p) const
QRect childrenRect () const
QRegion childrenRegion () const
void clearFocus ()
void clearMask ()
QCompletercompleter () const
QRect contentsRect () const
Qt::ContextMenuPolicy contextMenuPolicy () const
int count () const
void createWinId ()
int currentIndex () const
QString currentText () const
QCursor cursor () const
int depth () const
int devType () const
bool duplicatesEnabled () const
WId effectiveWinId () const
void ensurePolished () const
bool event (QEvent *event)
int findData (const QVariant &data, int role=Qt::UserRole, Qt::MatchFlags flags=Qt::MatchExactly|Qt::MatchCaseSensitive) const
int findText (const QString &text, Qt::MatchFlags flags=Qt::MatchExactly|Qt::MatchCaseSensitive) const
Qt::FocusPolicy focusPolicy () const
QWidgetfocusProxy () const
QWidgetfocusWidget () const
const QFontfont () const
QFontInfo fontInfo () const
QFontMetrics fontMetrics () const
QPalette::ColorRole foregroundRole () const
QRect frameGeometry () const
QSize frameSize () const
const QRectgeometry () const
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
void grabKeyboard ()
void grabMouse ()
void grabMouse (const QCursor &)
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
QGraphicsProxyWidgetgraphicsProxyWidget () const
Qt::HANDLE handle () const
bool hasFocus () const
bool hasFrame () const
bool hasMouseTracking () const
int height () const
virtual int heightForWidth (int) const
int heightMM () const
virtual void hidePopup ()
QSize iconSize () const
QInputContextinputContext ()
void insertAction (QAction *before, QAction *action)
void insertActions (QAction *before, QList< QAction * > actions)
void insertItem (int index, const QString &text, const QVariant &userData=QVariant())
void insertItem (int index, const QIcon &icon, const QString &text, const QVariant &userData=QVariant())
void insertItems (int index, const QStringList &texts)
InsertPolicy insertPolicy () const
void insertSeparator (int index)
WId internalWinId () const
bool isActiveWindow () const
bool isAncestorOf (const QWidget *child) const
bool isEditable () const
bool isEnabled () const
bool isEnabledTo (QWidget *) const
bool isEnabledToTLW () const
bool isFullScreen () const
bool isHidden () const
bool isLeftToRight () const
bool isMaximized () const
bool isMinimized () const
bool isModal () const
bool isRightToLeft () const
bool isTopLevel () const
bool isVisible () const
bool isVisibleTo (QWidget *) const
bool isWindow () const
bool isWindowModified () const
QVariant itemData (int index, int role=Qt::UserRole) const
QAbstractItemDelegateitemDelegate () const
QIcon itemIcon (int index) const
QString itemText (int index) const
QLayoutlayout () const
Qt::LayoutDirection layoutDirection () const
QLineEditlineEdit () const
QLocale locale () const
int logicalDpiX () const
int logicalDpiY () const
QPoint mapFrom (QWidget *, const QPoint &) const
QPoint mapFromGlobal (const QPoint &) const
QPoint mapFromParent (const QPoint &) const
QPoint mapTo (QWidget *, const QPoint &) const
QPoint mapToGlobal (const QPoint &) const
QPoint mapToParent (const QPoint &) const
QRegion mask () const
int maxCount () const
int maximumHeight () const
QSize maximumSize () const
int maximumWidth () const
int maxVisibleItems () const
int minimumContentsLength () const
int minimumHeight () const
QSize minimumSize () const
QSize minimumSizeHint () const
int minimumWidth () const
QAbstractItemModelmodel () const
int modelColumn () const
void move (int x, int y)
void move (const QPoint &)
QWidgetnativeParentWidget () const
QWidgetnextInFocusChain () const
QRect normalGeometry () const
int numColors () const
void overrideWindowFlags (Qt::WindowFlags type)
void overrideWindowState (Qt::WindowStates state)
QPaintEnginepaintEngine () const
bool paintingActive () const
const QPalettepalette () const
QWidgetparentWidget () const
int physicalDpiX () const
int physicalDpiY () const
QPoint pos () const
 QComboBox (QWidget *parent=0)
QRect rect () const
void releaseKeyboard ()
void releaseMouse ()
void releaseShortcut (int id)
void removeAction (QAction *action)
void removeItem (int index)
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
void repaint (int x, int y, int w, int h)
void repaint (const QRect &)
void repaint (const QRegion &)
void resize (const QSize &)
void resize (int w, int h)
bool restoreGeometry (const QByteArray &geometry)
QModelIndex rootModelIndex () const
QByteArray saveGeometry () const
void scroll (int dx, int dy, const QRect &)
void scroll (int dx, int dy)
void setAcceptDrops (bool on)
void setAccessibleDescription (const QString &description)
void setAccessibleName (const QString &name)
void setAttribute (Qt::WidgetAttribute, bool on=true)
void setAutoCompletion (bool enable)
void setAutoCompletionCaseSensitivity (Qt::CaseSensitivity sensitivity)
void setAutoFillBackground (bool enabled)
void setBackgroundRole (QPalette::ColorRole)
void setBaseSize (const QSize &)
void setBaseSize (int basew, int baseh)
void setCompleter (QCompleter *c)
void setContentsMargins (int left, int top, int right, int bottom)
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
void setCursor (const QCursor &)
void setDuplicatesEnabled (bool enable)
void setEditable (bool editable)
void setFixedHeight (int h)
void setFixedSize (const QSize &)
void setFixedSize (int w, int h)
void setFixedWidth (int w)
void setFocus (Qt::FocusReason reason)
void setFocusPolicy (Qt::FocusPolicy policy)
void setFocusProxy (QWidget *)
void setFont (const QFont &)
void setForegroundRole (QPalette::ColorRole)
void setFrame (bool)
void setGeometry (const QRect &)
void setGeometry (int x, int y, int w, int h)
void setIconSize (const QSize &size)
void setInputContext (QInputContext *)
void setInsertPolicy (InsertPolicy policy)
void setItemData (int index, const QVariant &value, int role=Qt::UserRole)
void setItemDelegate (QAbstractItemDelegate *delegate)
void setItemIcon (int index, const QIcon &icon)
void setItemText (int index, const QString &text)
void setLayout (QLayout *)
void setLayoutDirection (Qt::LayoutDirection direction)
void setLineEdit (QLineEdit *edit)
void setLocale (const QLocale &locale)
void setMask (const QBitmap &)
void setMask (const QRegion &)
void setMaxCount (int max)
void setMaximumHeight (int maxh)
void setMaximumSize (const QSize &)
void setMaximumSize (int maxw, int maxh)
void setMaximumWidth (int maxw)
void setMaxVisibleItems (int maxItems)
void setMinimumContentsLength (int characters)
void setMinimumHeight (int minh)
void setMinimumSize (int minw, int minh)
void setMinimumSize (const QSize &)
void setMinimumWidth (int minw)
void setModel (QAbstractItemModel *model)
void setModelColumn (int visibleColumn)
void setMouseTracking (bool enable)
void setPalette (const QPalette &)
void setParent (QWidget *parent, Qt::WindowFlags f)
void setParent (QWidget *parent)
void setRootModelIndex (const QModelIndex &index)
void setShortcutAutoRepeat (int id, bool enable=true)
void setShortcutEnabled (int id, bool enable=true)
void setSizeAdjustPolicy (SizeAdjustPolicy policy)
void setSizeIncrement (int w, int h)
void setSizeIncrement (const QSize &)
void setSizePolicy (QSizePolicy)
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
void setStatusTip (const QString &)
void setStyle (QStyle *)
void setToolTip (const QString &)
void setUpdatesEnabled (bool enable)
void setValidator (const QValidator *v)
void setView (QAbstractItemView *itemView)
void setWhatsThis (const QString &)
void setWindowFilePath (const QString &filePath)
void setWindowFlags (Qt::WindowFlags type)
void setWindowIcon (const QIcon &icon)
void setWindowIconText (const QString &)
void setWindowModality (Qt::WindowModality windowModality)
void setWindowOpacity (qreal level)
void setWindowRole (const QString &)
void setWindowState (Qt::WindowStates state)
void setWindowSurface (QWindowSurface *surface)
virtual void showPopup ()
QSize size () const
SizeAdjustPolicy sizeAdjustPolicy () const
QSize sizeHint () const
QSize sizeIncrement () const
QSizePolicy sizePolicy () const
void stackUnder (QWidget *)
QString statusTip () const
QStylestyle () const
QString styleSheet () const
bool testAttribute (Qt::WidgetAttribute) const
QString toolTip () const
QWidgettopLevelWidget () const
bool underMouse () const
void unsetCursor ()
void unsetLayoutDirection ()
void unsetLocale ()
void update (int x, int y, int w, int h)
void update (const QRegion &)
void update (const QRect &)
void updateGeometry ()
bool updatesEnabled () const
const QValidatorvalidator () const
QAbstractItemViewview () const
QRegion visibleRegion () const
QString whatsThis () const
int width () const
int widthMM () const
QWidgetwindow () const
QString windowFilePath () const
Qt::WindowFlags windowFlags () const
QIcon windowIcon () const
QString windowIconText () const
Qt::WindowModality windowModality () const
qreal windowOpacity () const
QString windowRole () const
Qt::WindowStates windowState () const
QWindowSurfacewindowSurface () const
QString windowTitle () const
Qt::WindowType windowType () const
WId winId () const
int x () const
int y () const
 ~QComboBox ()

Static Public Member Functions

static QWidgetfind (WId)
static QWidgetkeyboardGrabber ()
static QWidgetmouseGrabber ()
static void setTabOrder (QWidget *, QWidget *)

Protected Slots

void updateMicroFocus ()

Protected Member Functions

virtual void actionEvent (QActionEvent *)
void changeEvent (QEvent *e)
virtual void closeEvent (QCloseEvent *)
void contextMenuEvent (QContextMenuEvent *e)
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
virtual void dragEnterEvent (QDragEnterEvent *)
virtual void dragLeaveEvent (QDragLeaveEvent *)
virtual void dragMoveEvent (QDragMoveEvent *)
virtual void dropEvent (QDropEvent *)
virtual void enabledChange (bool)
virtual void enterEvent (QEvent *)
void focusInEvent (QFocusEvent *e)
bool focusNextChild ()
virtual bool focusNextPrevChild (bool next)
void focusOutEvent (QFocusEvent *e)
bool focusPreviousChild ()
virtual void fontChange (const QFont &)
void hideEvent (QHideEvent *e)
void initStyleOption (QStyleOptionComboBox *option) const
void inputMethodEvent (QInputMethodEvent *)
QVariant inputMethodQuery (Qt::InputMethodQuery) const
void keyPressEvent (QKeyEvent *e)
void keyReleaseEvent (QKeyEvent *e)
virtual void languageChange ()
virtual void leaveEvent (QEvent *)
int metric (PaintDeviceMetric) const
virtual void mouseDoubleClickEvent (QMouseEvent *)
virtual void mouseMoveEvent (QMouseEvent *)
void mousePressEvent (QMouseEvent *e)
void mouseReleaseEvent (QMouseEvent *e)
virtual void moveEvent (QMoveEvent *)
void paintEvent (QPaintEvent *e)
virtual void paletteChange (const QPalette &)
 QComboBox (QComboBoxPrivate &, QWidget *)
void resetInputContext ()
void resizeEvent (QResizeEvent *e)
void showEvent (QShowEvent *e)
virtual void styleChange (QStyle &)
virtual void tabletEvent (QTabletEvent *)
void wheelEvent (QWheelEvent *e)
virtual void windowActivationChange (bool)

Protected Attributes

ushort painters


bool acceptDrops
 whether drop events are enabled for this widget
QString accessibleDescription
 the widget's description as seen by assistive technologies
QString accessibleName
 the widget's name as seen by assistive technologies
bool autoCompletion
 whether the combobox provides auto-completion for editable items
Qt::CaseSensitivity autoCompletionCaseSensitivity
 whether string comparisons are case-sensitive or case-insensitive for auto-completion
bool autoFillBackground
 whether the widget background is filled automatically
QSize baseSize
 the base size of the widget
QRect childrenRect
 the bounding rectangle of the widget's children
QRegion childrenRegion
 the combined region occupied by the widget's children
Qt::ContextMenuPolicy contextMenuPolicy
 how the widget shows a context menu
int count
 the number of items in the combobox
int currentIndex
 the index of the current item in the combobox.
QString currentText
 the text of the current item
QCursor cursor
 the cursor shape for this widget
bool duplicatesEnabled
 whether the user can enter duplicate items into the combobox
bool editable
 whether the combo box can be edited by the user
bool enabled
 whether the widget is enabled
bool focus
 whether this widget (or its focus proxy) has the keyboard input focus
Qt::FocusPolicy focusPolicy
 the way the widget accepts keyboard focus
QFont font
 the font currently set for the widget
bool frame
 whether the combo box draws itself with a frame
QRect frameGeometry
 geometry of the widget relative to its parent including any window frame
QSize frameSize
 the size of the widget including any window frame
bool fullScreen
 whether the widget is shown in full screen mode
QRect geometry
 the geometry of the widget relative to its parent and excluding the window frame
int height
 the height of the widget excluding any window frame
QSize iconSize
 the size of the icons shown in the combobox.
InsertPolicy insertPolicy
 the policy used to determine where user-inserted items should appear in the combobox
bool isActiveWindow
 whether this widget's window is the active window
Qt::LayoutDirection layoutDirection
 the layout direction for this widget
QLocale locale
 the widget's locale
int maxCount
 the maximum number of items allowed in the combobox
bool maximized
 whether this widget is maximized
int maximumHeight
 the widget's maximum height in pixels
QSize maximumSize
 the widget's maximum size in pixels
int maximumWidth
 the widget's maximum width in pixels
int maxVisibleItems
 the maximum allowed size on screen of the combo box, measured in items
bool minimized
 whether this widget is minimized (iconified)
int minimumContentsLength
 the minimum number of characters that should fit into the combobox.
int minimumHeight
 the widget's minimum height in pixels
QSize minimumSize
 the widget's minimum size
QSize minimumSizeHint
 the recommended minimum size for the widget
int minimumWidth
 the widget's minimum width in pixels
bool modal
 whether the widget is a modal widget
int modelColumn
 the column in the model that is visible.
bool mouseTracking
 whether mouse tracking is enabled for the widget
QRect normalGeometry
 the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) top-level widget
QPalette palette
 the widget's palette
QPoint pos
 the position of the widget within its parent widget
QRect rect
 the internal geometry of the widget excluding any window frame
QSize size
 the size of the widget excluding any window frame
SizeAdjustPolicy sizeAdjustPolicy
 the policy describing how the size of the combobox changes when the content changes
QSize sizeHint
 the recommended size for the widget
QSize sizeIncrement
 the size increment of the widget
QSizePolicy sizePolicy
 the default layout behavior of the widget
QString statusTip
 the widget's status tip
QString styleSheet
 the widget's style sheet
QString toolTip
 the widget's tooltip
bool updatesEnabled
 whether updates are enabled
bool visible
 whether the widget is visible
QString whatsThis
 the widget's What's This help text.
int width
 the width of the widget excluding any window frame
QString windowFilePath
 the file path associated with a widget
QIcon windowIcon
 the widget's icon
QString windowIconText
 the widget's icon text
Qt::WindowModality windowModality
 which windows are blocked by the modal widget
bool windowModified
 whether the document shown in the window has unsaved changes
double windowOpacity
 The level of opacity for the window.
QString windowTitle
 the window title (caption)
int x
 the x coordinate of the widget relative to its parent including any window frame
int y
 the y coordinate of the widget relative to its parent and including any window frame

Private Member Functions

void void void void void _q_dataChanged (const QModelIndex &, const QModelIndex &)) Q_PRIVATE_SLOT(d_func()
void void _q_emitCurrentIndexChanged (const QModelIndex &index)) Q_PRIVATE_SLOT(d_func()
void _q_emitHighlighted (const QModelIndex &)) Q_PRIVATE_SLOT(d_func()
void void void void void void
void void void void 
_q_modelDestroyed ()) Q_PRIVATE_SLOT(d_func()
void void void void _q_resetButton ()) Q_PRIVATE_SLOT(d_func()
void void void _q_returnPressed ()) Q_PRIVATE_SLOT(d_func()
void void void void void void _q_rowsAboutToBeInserted (const QModelIndex &parent, int start, int end)) Q_PRIVATE_SLOT(d_func()
void void void void void void
void void 
_q_rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end)) Q_PRIVATE_SLOT(d_func()
void void void void void void void _q_rowsInserted (const QModelIndex &parent, int start, int end)) Q_PRIVATE_SLOT(d_func()
void void void void void void
void void void 
_q_rowsRemoved (const QModelIndex &parent, int start, int end)) Q_PRIVATE_SLOT(d_func()
 Q_PRIVATE_SLOT (d_func(), void _q_itemSelected(const QModelIndex &item)) Q_PRIVATE_SLOT(d_func()

Related Functions

(Note that these are not member functions.)

const Q_GUI_EXPORT QX11Infoqt_x11Info (const QPaintDevice *pd)

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 setItemText() functions are suitably overloaded. For editable comboboxes, the function clearEditText() is provided, to clear the displayed string without changing the combobox's contents.

There are two signals emitted if the current item of a combobox changes, currentIndexChanged() and activated(). currentIndexChanged() is always emitted regardless if the change was done programmatically or by user interaction, while activated() is only emitted when the change is caused by user interaction. The highlighted() signal is emitted when the user highlights an item in the combobox popup list. All three signals exist in two versions, one with a QString argument and one with an int argument. If the user selectes or highlights 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, insertItem() and insertItems() for example. Items can be changed with setItemText(). 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 setCompleter() and whether or not the user can add duplicates is set with setDuplicatesEnabled().

QComboBox uses the {Model/View Programming}{model/view framework} for its popup list and to store its items. By default a QStandardItemModel stores the items and a QListView subclass displays the popuplist. You can access the model and view directly (with model() and view()), but QComboBox also provides functions to set and get item data (e.g., setItemData() and itemText()). You can also set a new model and view (with setModel() and setView()). For the text and icon in the combobox label, the data in the model that has the Qt::DisplayRole and Qt::DecorationRole is used.

Comboboxes in the different built-in styles.

See also:
QLineEdit, QSpinBox, QRadioButton, QButtonGroup, {fowler}{GUI Design Handbook: Combo Box, Drop-Down List Box}

Definition at line 63 of file qcombobox.h.

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index