Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Protected Functions | Properties | List of all members
QComboBox Class Reference

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

#include <qcombobox.h>

Inheritance diagram for QComboBox:
QWidget QObject QPaintDevice QBooleanComboBox QFileDialogComboBox QFontComboBox

Public Types

enum  InsertPolicy {
  NoInsert, InsertAtTop, InsertAtCurrent, InsertAtBottom,
  InsertAfterCurrent, InsertBeforeCurrent, InsertAlphabetically
}
 This enum specifies what the QComboBox should do when a new string is entered by the user. More...
 
enum  SizeAdjustPolicy { AdjustToContents, AdjustToContentsOnFirstShow, AdjustToMinimumContentsLength, AdjustToMinimumContentsLengthWithIcon }
 This enum specifies how the size hint of the QComboBox should adjust when new content is added or content changes. More...
 
- Public Types inherited from QWidget
enum  RenderFlag { DrawWindowBackground = 0x1, DrawChildren = 0x2, IgnoreMask = 0x4 }
 This enum describes how to render the widget when calling QWidget::render(). More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 

Public Slots

void clear ()
 Clears the combobox, removing all items. More...
 
void clearEditText ()
 Clears the contents of the line edit used for editing in the combobox. More...
 
void setCurrentIndex (int index)
 
void setEditText (const QString &text)
 Sets the text in the combobox's text edit. More...
 
- Public Slots inherited from QWidget
bool close ()
 Closes this widget. More...
 
void hide ()
 Hides the widget. More...
 
void lower ()
 Lowers the widget to the bottom of the parent widget's stack. More...
 
void raise ()
 Raises this widget to the top of the parent widget's stack. More...
 
void repaint ()
 Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden. More...
 
void setDisabled (bool)
 Disables widget input events if disable is true; otherwise enables input events. More...
 
void setEnabled (bool)
 
void setFocus ()
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setHidden (bool hidden)
 Convenience function, equivalent to setVisible(!hidden). More...
 
QT_MOC_COMPAT void setShown (bool shown)
 Use setVisible(shown) instead. More...
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool)
 
void setWindowTitle (const QString &)
 
void show ()
 Shows the widget and its child widgets. More...
 
void showFullScreen ()
 Shows the widget in full-screen mode. More...
 
void showMaximized ()
 Shows the widget maximized. More...
 
void showMinimized ()
 Shows the widget minimized, as an icon. More...
 
void showNormal ()
 Restores the widget after it has been maximized or minimized. More...
 
void update ()
 Updates the widget unless updates are disabled or the widget is hidden. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void activated (int index)
 This signal is sent when the user chooses an item in the combobox. More...
 
void activated (const QString &)
 This signal is sent when the user chooses an item in the combobox. More...
 
void currentIndexChanged (int index)
 This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. More...
 
void currentIndexChanged (const QString &)
 This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. More...
 
void editTextChanged (const QString &)
 This signal is emitted when the text in the combobox's line edit widget is changed. More...
 
void highlighted (int index)
 This signal is sent when an item in the combobox popup list is highlighted by the user. More...
 
void highlighted (const QString &)
 This signal is sent when an item in the combobox popup list is highlighted by the user. More...
 
- Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

void addItem (const QString &text, const QVariant &userData=QVariant())
 Adds an item to the combobox with the given text, and containing the specified userData (stored in the Qt::UserRole). More...
 
void addItem (const QIcon &icon, const QString &text, const QVariant &userData=QVariant())
 Adds an item to the combobox with the given icon and text, and containing the specified userData (stored in the Qt::UserRole). More...
 
void addItems (const QStringList &texts)
 Adds each of the strings in the given texts to the combobox. More...
 
bool autoCompletion () const
 
Qt::CaseSensitivity autoCompletionCaseSensitivity () const
 
QCompletercompleter () const
 Returns the completer that is used to auto complete text input for the combobox. More...
 
int count () const
 
int currentIndex () const
 
QString currentText () const
 
bool duplicatesEnabled () const
 
bool event (QEvent *event)
 Reimplemented Function More...
 
int findData (const QVariant &data, int role=Qt::UserRole, Qt::MatchFlags flags=static_cast< Qt::MatchFlags >(Qt::MatchExactly|Qt::MatchCaseSensitive)) const
 Returns the index of the item containing the given data for the given role; otherwise returns -1. More...
 
int findText (const QString &text, Qt::MatchFlags flags=static_cast< Qt::MatchFlags >(Qt::MatchExactly|Qt::MatchCaseSensitive)) const
 Returns the index of the item containing the given text; otherwise returns -1. More...
 
bool hasFrame () const
 
virtual void hidePopup ()
 Hides the list of items in the combobox if it is currently visible and resets the internal state, so that if the custom pop-up was shown inside the reimplemented showPopup(), then you also need to reimplement the hidePopup() function to hide your custom pop-up and call the base class implementation to reset the internal state whenever your custom pop-up widget is hidden. More...
 
QSize iconSize () const
 
void insertItem (int index, const QString &text, const QVariant &userData=QVariant())
 Inserts the text and userData (stored in the Qt::UserRole) into the combobox at the given index. More...
 
void insertItem (int index, const QIcon &icon, const QString &text, const QVariant &userData=QVariant())
 Inserts the icon, text and userData (stored in the Qt::UserRole) into the combobox at the given index. More...
 
void insertItems (int index, const QStringList &texts)
 Inserts the strings from the list into the combobox as separate items, starting at the index specified. More...
 
InsertPolicy insertPolicy () const
 
void insertSeparator (int index)
 Inserts a separator item into the combobox at the given index. More...
 
bool isEditable () const
 
QVariant 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. More...
 
QAbstractItemDelegateitemDelegate () const
 Returns the item delegate used by the popup list view. More...
 
QIcon itemIcon (int index) const
 Returns the icon for the given index in the combobox. More...
 
QString itemText (int index) const
 Returns the text for the given index in the combobox. More...
 
QLineEditlineEdit () const
 Returns the line edit used to edit items in the combobox, or 0 if there is no line edit. More...
 
int maxCount () const
 
int maxVisibleItems () const
 
int minimumContentsLength () const
 
QSize minimumSizeHint () const
 Reimplemented Function More...
 
QAbstractItemModelmodel () const
 Returns the model used by the combobox. More...
 
int modelColumn () const
 
 QComboBox (QWidget *parent=0)
 Constructs a combobox with the given parent, using the default model QStandardItemModel. More...
 
void removeItem (int index)
 Removes the item at the given index from the combobox. More...
 
QModelIndex rootModelIndex () const
 Returns the root model item index for the items in the combobox. More...
 
void setAutoCompletion (bool enable)
 Use setCompleter() instead. More...
 
void setAutoCompletionCaseSensitivity (Qt::CaseSensitivity sensitivity)
 Use setCompleter() and QCompleter::setCaseSensitivity() instead. More...
 
void setCompleter (QCompleter *c)
 
void setDuplicatesEnabled (bool enable)
 
void setEditable (bool editable)
 
void setFrame (bool)
 
void setIconSize (const QSize &size)
 
void setInsertPolicy (InsertPolicy policy)
 
void 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. More...
 
void setItemDelegate (QAbstractItemDelegate *delegate)
 Sets the item delegate for the popup list view. More...
 
void setItemIcon (int index, const QIcon &icon)
 Sets the icon for the item on the given index in the combobox. More...
 
void setItemText (int index, const QString &text)
 Sets the text for the item on the given index in the combobox. More...
 
void setLineEdit (QLineEdit *edit)
 Sets the line edit to use instead of the current line edit widget. More...
 
void setMaxCount (int max)
 
void setMaxVisibleItems (int maxItems)
 
void setMinimumContentsLength (int characters)
 
void setModel (QAbstractItemModel *model)
 Sets the model to be model. More...
 
void setModelColumn (int visibleColumn)
 
void setRootModelIndex (const QModelIndex &index)
 Sets the root model item index for the items in the combobox. More...
 
void setSizeAdjustPolicy (SizeAdjustPolicy policy)
 
void setValidator (const QValidator *v)
 Sets the validator to use instead of the current validator. More...
 
void setView (QAbstractItemView *itemView)
 Sets the view to be used in the combobox popup to the given itemView. More...
 
virtual void showPopup ()
 Displays the list of items in the combobox. More...
 
SizeAdjustPolicy sizeAdjustPolicy () const
 
QSize sizeHint () const
 This implementation caches the size hint to avoid resizing when the contents change dynamically. More...
 
const QValidatorvalidator () const
 Returns the validator that is used to constrain text input for the combobox. More...
 
QAbstractItemViewview () const
 Returns the list view used for the combobox popup. More...
 
 ~QComboBox ()
 Destroys the combobox. More...
 
- Public Functions inherited from QWidget
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 Returns the (possibly empty) list of this widget's actions. More...
 
void activateWindow ()
 Sets the top-level widget containing this widget to be the active window. More...
 
void addAction (QAction *action)
 Appends the action action to this widget's list of actions. More...
 
void addActions (QList< QAction *> actions)
 Appends the actions actions to this widget's list of actions. More...
 
void adjustSize ()
 Adjusts the size of the widget to fit its contents. More...
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 Returns the background role of the widget. More...
 
QSize baseSize () const
 
QWidgetchildAt (int x, int y) const
 Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system. More...
 
QWidgetchildAt (const QPoint &p) const
 Returns the visible child widget at point p in the widget's own coordinate system. More...
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 Takes keyboard input focus from the widget. More...
 
void clearMask ()
 Removes any mask set by setMask(). More...
 
QMargins contentsMargins () const
 The contentsMargins function returns the widget's contents margins. More...
 
QRect contentsRect () const
 Returns the area inside the widget's margins. More...
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
void createWinId ()
 
QCursor cursor () const
 
int devType () const
 
WId effectiveWinId () const
 Returns the effective window system identifier of the widget, i. More...
 
void ensurePolished () const
 Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette). More...
 
Qt::FocusPolicy focusPolicy () const
 
QWidgetfocusProxy () const
 Returns the focus proxy, or 0 if there is no focus proxy. More...
 
QWidgetfocusWidget () const
 Returns the last child of this widget that setFocus had been called on. More...
 
const QFontfont () const
 
QFontInfo fontInfo () const
 Returns the font info for the widget's current font. More...
 
QFontMetrics fontMetrics () const
 Returns the font metrics for the widget's current font. More...
 
QPalette::ColorRole foregroundRole () const
 Returns the foreground role. More...
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 Returns the widget's contents margins for left, top, right, and bottom. More...
 
HDC getDC () const
 Returns the window system handle of the widget, for low-level access. More...
 
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 Subscribes the widget to a given gesture with specific flags. More...
 
void grabKeyboard ()
 Grabs the keyboard input. More...
 
void grabMouse ()
 Grabs the mouse input. More...
 
void grabMouse (const QCursor &)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context. More...
 
QGraphicsEffectgraphicsEffect () const
 The graphicsEffect function returns a pointer to the widget's graphics effect. More...
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns 0. More...
 
bool hasFocus () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int) const
 Returns the preferred height for this widget, given the width w. More...
 
QInputContextinputContext ()
 This function returns the QInputContext for this widget. More...
 
Qt::InputMethodHints inputMethodHints () const
 
void insertAction (QAction *before, QAction *action)
 Inserts the action action to this widget's list of actions, before the action before. More...
 
void insertActions (QAction *before, QList< QAction *> actions)
 Inserts the actions actions to this widget's list of actions, before the action before. More...
 
WId internalWinId () const
 Returns the window system identifier of the widget, or 0 if the widget is not created yet. More...
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child, and both widgets are within the same window; otherwise returns false. More...
 
bool isEnabled () const
 
bool isEnabledTo (QWidget *) const
 Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false. More...
 
bool isEnabledToTLW () const
 This function is deprecated. More...
 
bool isFullScreen () const
 
bool isHidden () const
 Returns true if the widget is hidden, otherwise returns false. More...
 
bool isLeftToRight () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isRightToLeft () const
 
bool isTopLevel () const
 Use isWindow() instead. More...
 
bool isVisible () const
 
bool isVisibleTo (QWidget *) const
 Returns true if this widget would become visible if ancestor is shown; otherwise returns false. More...
 
bool isWindow () const
 Returns true if the widget is an independent window, otherwise returns false. More...
 
bool isWindowModified () const
 
QLayoutlayout () const
 Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed. More...
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
Qt::HANDLE macCGHandle () const
 Returns the CoreGraphics handle of the widget. More...
 
Qt::HANDLE macQDHandle () const
 Returns the QuickDraw handle of the widget. More...
 
QPoint mapFrom (QWidget *, const QPoint &) const
 Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system. More...
 
QPoint mapFromGlobal (const QPoint &) const
 Translates the global screen coordinate pos to widget coordinates. More...
 
QPoint mapFromParent (const QPoint &) const
 Translates the parent widget coordinate pos to widget coordinates. More...
 
QPoint mapTo (QWidget *, const QPoint &) const
 Translates the widget coordinate pos to the coordinate system of parent. More...
 
QPoint mapToGlobal (const QPoint &) const
 Translates the widget coordinate pos to global screen coordinates. More...
 
QPoint mapToParent (const QPoint &) const
 Translates the widget coordinate pos to a coordinate in the parent widget. More...
 
QRegion mask () const
 Returns the mask currently set on a widget. More...
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (int x, int y)
 This corresponds to move(QPoint(x, y)). More...
 
void move (const QPoint &)
 
QWidgetnativeParentWidget () const
 Returns the native parent for this widget, i. More...
 
QWidgetnextInFocusChain () const
 Returns the next widget in this widget's focus chain. More...
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags type)
 Sets the window flags for the widget to flags, without telling the window system. More...
 
void overrideWindowState (Qt::WindowStates state)
 
QPaintEnginepaintEngine () const
 Returns the widget's paint engine. More...
 
const QPalettepalette () const
 
QWidgetparentWidget () const
 Returns the parent of this widget, or 0 if it does not have any parent widget. More...
 
QPoint pos () const
 
QWidgetpreviousInFocusChain () const
 The previousInFocusChain function returns the previous widget in this widget's focus chain. More...
 
 QWidget (QWidget *parent=0, Qt::WindowFlags f=0)
 Constructs a widget which is a child of parent, with widget flags set to f. More...
 
QRect rect () const
 
void releaseDC (HDC) const
 Releases the HDC hdc acquired by a previous call to getDC(). More...
 
void releaseKeyboard ()
 Releases the keyboard grab. More...
 
void releaseMouse ()
 Releases the mouse grab. More...
 
void releaseShortcut (int id)
 Removes the shortcut with the given id from Qt's shortcut system. More...
 
void removeAction (QAction *action)
 Removes the action action from this widget's list of actions. More...
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the sourceRegion of this widget into the target using renderFlags to determine how to render. More...
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the widget into the painter's QPainter::device(). More...
 
void repaint (int x, int y, int w, int h)
 This version repaints a rectangle (x, y, w, h) inside the widget. More...
 
void repaint (const QRect &)
 This version repaints a rectangle rect inside the widget. More...
 
void repaint (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void resize (int w, int h)
 This corresponds to resize(QSize(w, h)). More...
 
void resize (const QSize &)
 
bool restoreGeometry (const QByteArray &geometry)
 Restores the geometry and state top-level widgets stored in the byte array geometry. More...
 
QByteArray saveGeometry () const
 Saves the current geometry and state for top-level widgets. More...
 
void scroll (int dx, int dy)
 Scrolls the widget including its children dx pixels to the right and dy downward. More...
 
void scroll (int dx, int dy, const QRect &)
 This version only scrolls r and does not move the children of the widget. More...
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute, bool on=true)
 Sets the attribute attribute on this widget if on is true; otherwise clears the attribute. More...
 
void setAutoFillBackground (bool enabled)
 
void setBackgroundRole (QPalette::ColorRole)
 Sets the background role of the widget to role. More...
 
void setBaseSize (const QSize &)
 
void setBaseSize (int basew, int baseh)
 This corresponds to setBaseSize(QSize(basew, baseh)). More...
 
void setContentsMargins (int left, int top, int right, int bottom)
 Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom. More...
 
void setContentsMargins (const QMargins &margins)
 The setContentsMargins function sets the margins around the widget's contents. More...
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &)
 
void setFixedHeight (int h)
 Sets both the minimum and maximum heights of the widget to h without changing the widths. More...
 
void setFixedSize (const QSize &)
 Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking. More...
 
void setFixedSize (int w, int h)
 Sets the width of the widget to w and the height to h. More...
 
void setFixedWidth (int w)
 Sets both the minimum and maximum width of the widget to w without changing the heights. More...
 
void setFocus (Qt::FocusReason reason)
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *)
 Sets the widget's focus proxy to widget w. More...
 
void setFont (const QFont &)
 Use the single-argument overload instead. More...
 
void setForegroundRole (QPalette::ColorRole)
 Sets the foreground role of the widget to role. More...
 
void setGeometry (int x, int y, int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to setGeometry(QRect(x, y, w, h)). More...
 
void setGeometry (const QRect &)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 The setGraphicsEffect function is for setting the widget's graphics effect. More...
 
void setInputContext (QInputContext *)
 This function sets the input context context on this widget. More...
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *)
 Sets the layout manager for this widget to layout. More...
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &)
 Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. More...
 
void setMask (const QRegion &)
 Causes only the parts of the widget which overlap region to be visible. More...
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &)
 
void setMaximumSize (int maxw, int maxh)
 This function corresponds to setMaximumSize(QSize(maxw, maxh)). More...
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &)
 
void setMinimumSize (int minw, int minh)
 This function corresponds to setMinimumSize(QSize(minw, minh)). More...
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &)
 Use the single-argument overload instead. More...
 
void setParent (QWidget *parent)
 Sets the parent of the widget to parent, and resets the window flags. More...
 
void setParent (QWidget *parent, Qt::WindowFlags f)
 This function also takes widget flags, f as an argument. More...
 
void setShortcutAutoRepeat (int id, bool enable=true)
 If enable is true, auto repeat of the shortcut with the given id is enabled; otherwise it is disabled. More...
 
void setShortcutEnabled (int id, bool enable=true)
 If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled. More...
 
void setSizeIncrement (const QSize &)
 
void setSizeIncrement (int w, int h)
 Sets the x (width) size increment to w and the y (height) size increment to h. More...
 
void setSizePolicy (QSizePolicy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width. More...
 
void setStatusTip (const QString &)
 
void setStyle (QStyle *)
 Sets the widget's GUI style to style. More...
 
void setToolTip (const QString &)
 
void setUpdatesEnabled (bool enable)
 
void setupUi (QWidget *widget)
 Sets up the user interface for the specified widget. More...
 
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 &)
 Sets the window's role to role. More...
 
void setWindowState (Qt::WindowStates state)
 Sets the window state to windowState. More...
 
void setWindowSurface (QWindowSurface *surface)
 Sets the window surface to be the surface specified. More...
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *)
 Places the widget under w in the parent widget's stack. More...
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute) const
 Returns true if attribute attribute is set on this widget; otherwise returns false. More...
 
QString toolTip () const
 
QWidgettopLevelWidget () const
 
bool underMouse () const
 Returns true if the widget is under the mouse cursor; otherwise returns false. More...
 
void ungrabGesture (Qt::GestureType type)
 Unsubscribes the widget from a given gesture type. More...
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (int x, int y, int w, int h)
 This version updates a rectangle (x, y, w, h) inside the widget. More...
 
void update (const QRect &)
 This version updates a rectangle rect inside the widget. More...
 
void update (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void updateGeometry ()
 Notifies the layout system that this widget has changed and may need to change geometry. More...
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 Returns the unobscured region where paint events can occur. More...
 
QString whatsThis () const
 
int width () const
 
QWidgetwindow () const
 Returns the window for this widget, i.e. More...
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 Window flags are a combination of a type (e. More...
 
QIcon windowIcon () const
 
QString windowIconText () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 Returns the window's role, or an empty string. More...
 
Qt::WindowStates windowState () const
 Returns the current window state. More...
 
QWindowSurfacewindowSurface () const
 Returns the QWindowSurface this widget will be drawn into. More...
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 Returns the window type of this widget. More...
 
WId winId () const
 Returns the window system identifier of the widget. More...
 
int x () const
 
const QX11Infox11Info () const
 Returns information about the configuration of the X display used to display the widget. More...
 
Qt::HANDLE x11PictureHandle () const
 Returns the X11 Picture handle of the widget for XRender support. More...
 
int y () const
 
 ~QWidget ()
 Destroys the widget. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Protected Functions

void changeEvent (QEvent *e)
 Reimplemented Function More...
 
void contextMenuEvent (QContextMenuEvent *e)
 Reimplemented Function More...
 
void focusInEvent (QFocusEvent *e)
 Reimplemented Function More...
 
void focusOutEvent (QFocusEvent *e)
 Reimplemented Function More...
 
void hideEvent (QHideEvent *e)
 Reimplemented Function More...
 
void initStyleOption (QStyleOptionComboBox *option) const
 Initialize option with the values from this QComboBox. More...
 
void inputMethodEvent (QInputMethodEvent *)
 Reimplemented Function More...
 
QVariant inputMethodQuery (Qt::InputMethodQuery) const
 Reimplemented Function More...
 
void keyPressEvent (QKeyEvent *e)
 Reimplemented Function More...
 
void keyReleaseEvent (QKeyEvent *e)
 Reimplemented Function More...
 
void mousePressEvent (QMouseEvent *e)
 Reimplemented Function More...
 
void mouseReleaseEvent (QMouseEvent *e)
 Reimplemented Function More...
 
void paintEvent (QPaintEvent *e)
 Reimplemented Function More...
 
 QComboBox (QComboBoxPrivate &, QWidget *)
 
void resizeEvent (QResizeEvent *e)
 Reimplemented Function More...
 
void showEvent (QShowEvent *e)
 Reimplemented Function More...
 
void wheelEvent (QWheelEvent *e)
 Reimplemented Function More...
 
- Protected Functions inherited from QWidget
virtual void actionEvent (QActionEvent *)
 This event handler is called with the given event whenever the widget's actions are changed. More...
 
virtual void closeEvent (QCloseEvent *)
 This event handler is called with the given event when Qt receives a window close request for a top-level widget from the window system. More...
 
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
 Creates a new widget window if window is 0, otherwise sets the widget's window to window. More...
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 Frees up window system resources. More...
 
virtual void dragEnterEvent (QDragEnterEvent *)
 This event handler is called when a drag is in progress and the mouse enters this widget. More...
 
virtual void dragLeaveEvent (QDragLeaveEvent *)
 This event handler is called when a drag is in progress and the mouse leaves this widget. More...
 
virtual void dragMoveEvent (QDragMoveEvent *)
 This event handler is called if a drag is in progress, and when any of the following conditions occur: the cursor enters this widget, the cursor moves within this widget, or a modifier key is pressed on the keyboard while this widget has the focus. More...
 
virtual void dropEvent (QDropEvent *)
 This event handler is called when the drag is dropped on this widget. More...
 
virtual void enabledChange (bool)
 
virtual void enterEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter. More...
 
bool focusNextChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual bool focusNextPrevChild (bool next)
 Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
bool focusPreviousChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual void fontChange (const QFont &)
 
virtual void languageChange ()
 
virtual void leaveEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the event parameter. More...
 
virtual bool macEvent (EventHandlerCallRef, EventRef)
 This special event handler can be reimplemented in a subclass to receive native Macintosh events. More...
 
int metric (PaintDeviceMetric) const
 Internal implementation of the virtual QPaintDevice::metric() function. More...
 
virtual void mouseDoubleClickEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse double click events for the widget. More...
 
virtual void mouseMoveEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse move events for the widget. More...
 
virtual void moveEvent (QMoveEvent *)
 This event handler can be reimplemented in a subclass to receive widget move events which are passed in the event parameter. More...
 
virtual void paletteChange (const QPalette &)
 
 QWidget (QWidgetPrivate &d, QWidget *parent, Qt::WindowFlags f)
 
virtual bool qwsEvent (QWSEvent *)
 This special event handler can be reimplemented in a subclass to receive native Qt for Embedded Linux events which are passed in the event parameter. More...
 
void resetInputContext ()
 This function can be called on the widget that currently has focus to reset the input method operating on it. More...
 
virtual void styleChange (QStyle &)
 
virtual void tabletEvent (QTabletEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive tablet events for the widget. More...
 
virtual void windowActivationChange (bool)
 
virtual bool winEvent (MSG *message, long *result)
 This special event handler can be reimplemented in a subclass to receive native Windows events which are passed in the message parameter. More...
 
virtual bool x11Event (XEvent *)
 This special event handler can be reimplemented in a subclass to receive native X11 events passed in the event parameter. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Properties

bool autoCompletion
 whether the combobox provides auto-completion for editable items More...
 
Qt::CaseSensitivity autoCompletionCaseSensitivity
 whether string comparisons are case-sensitive or case-insensitive for auto-completion More...
 
int count
 the number of items in the combobox More...
 
int currentIndex
 the index of the current item in the combobox. More...
 
QString currentText
 the current text More...
 
bool duplicatesEnabled
 whether the user can enter duplicate items into the combobox More...
 
bool editable
 whether the combo box can be edited by the user More...
 
bool frame
 whether the combo box draws itself with a frame More...
 
QSize iconSize
 the size of the icons shown in the combobox. More...
 
InsertPolicy insertPolicy
 the policy used to determine where user-inserted items should appear in the combobox More...
 
int maxCount
 the maximum number of items allowed in the combobox More...
 
int maxVisibleItems
 the maximum allowed size on screen of the combo box, measured in items More...
 
int minimumContentsLength
 the minimum number of characters that should fit into the combobox. More...
 
int modelColumn
 the column in the model that is visible. More...
 
SizeAdjustPolicy sizeAdjustPolicy
 the policy describing how the size of the combobox changes when the content changes More...
 

Additional Inherited Members

- Static Public Functions inherited from QWidget
static QWidgetfind (WId)
 Returns a pointer to the widget with window identifer/handle id. More...
 
static QWidgetkeyboardGrabber ()
 Returns the widget that is currently grabbing the keyboard input. More...
 
static QWidgetmouseGrabber ()
 Returns the widget that is currently grabbing the mouse input. More...
 
static void setTabOrder (QWidget *, QWidget *)
 Puts the second widget after the first widget in the focus order. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 Updates the widget's micro focus. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Variables inherited from QPaintDevice
ushort painters
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

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 selects 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. Note that you cannot alter the QAbstractItemView::SelectionMode of the view(), e.g., by using QAbstractItemView::setSelectionMode().

qstyle-comboboxes.png
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 62 of file qcombobox.h.

Enumerations

◆ InsertPolicy

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

  • NoInsert The string will not be inserted into the combobox.
  • InsertAtTop The string will be inserted as the first item in the combobox.
  • InsertAtCurrent The current item will be replaced by the string.
  • InsertAtBottom The string will be inserted after the last item in the combobox.
  • InsertAfterCurrent The string is inserted after the current item in the combobox.
  • InsertBeforeCurrent The string is inserted before the current item in the combobox.
  • InsertAlphabetically The string is inserted in the alphabetic order in the combobox.
  • NoInsertion
  • AtTop
  • AtCurrent
  • AtBottom
  • AfterCurrent
  • BeforeCurrent
Enumerator
NoInsert 
InsertAtTop 
InsertAtCurrent 
InsertAtBottom 
InsertAfterCurrent 
InsertBeforeCurrent 
InsertAlphabetically 

Definition at line 119 of file qcombobox.h.

119  {
120  NoInsert,
121  InsertAtTop,
127 #if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN)
128  ,
129  NoInsertion = NoInsert,
130  AtTop = InsertAtTop,
131  AtCurrent = InsertAtCurrent,
132  AtBottom = InsertAtBottom,
133  AfterCurrent = InsertAfterCurrent,
134  BeforeCurrent = InsertBeforeCurrent
135 #endif
136  };

◆ SizeAdjustPolicy

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

  • AdjustToContents The combobox will always adjust to the contents
  • AdjustToContentsOnFirstShow The combobox will adjust to its contents the first time it is shown.
  • AdjustToMinimumContentsLength Use AdjustToContents or AdjustToContentsOnFirstShow instead.
  • AdjustToMinimumContentsLengthWithIcon The combobox will adjust to minimumContentsLength plus space for an icon. For performance reasons use this policy on large models.
Enumerator
AdjustToContents 
AdjustToContentsOnFirstShow 
AdjustToMinimumContentsLength 
AdjustToMinimumContentsLengthWithIcon 

Definition at line 144 of file qcombobox.h.

Constructors and Destructors

◆ QComboBox() [1/2]

QComboBox::QComboBox ( QWidget parent = 0)
explicit

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

Definition at line 870 of file qcombobox.cpp.

Referenced by QComboBox().

871  : QWidget(*new QComboBoxPrivate(), parent, 0)
872 {
873  Q_D(QComboBox);
874  d->init();
875 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ ~QComboBox()

QComboBox::~QComboBox ( )

Destroys the combobox.

Definition at line 1325 of file qcombobox.cpp.

1326 {
1327  // ### check delegateparent and delete delegate if us?
1328  Q_D(QComboBox);
1329 
1330  QT_TRY {
1331  disconnect(d->model, SIGNAL(destroyed()),
1332  this, SLOT(_q_modelDestroyed()));
1333  } QT_CATCH(...) {
1334  ; // objects can't throw in destructor
1335  }
1336 }
double d
Definition: qnumeric_p.h:62
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_D(Class)
Definition: qglobal.h:2482
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
#define QT_CATCH(A)
Definition: qglobal.h:1537
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
#define QT_TRY
Definition: qglobal.h:1536

◆ QComboBox() [2/2]

QComboBox::QComboBox ( QComboBoxPrivate dd,
QWidget parent 
)
protected
Warning
This function is not part of the public interface.

Definition at line 880 of file qcombobox.cpp.

881  : QWidget(dd, parent, 0)
882 {
883  Q_D(QComboBox);
884  d->init();
885 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

Functions

◆ activated [1/2]

void QComboBox::activated ( int  index)
signal

This signal is sent when the user chooses an item in the combobox.

The item's index is passed. Note that this signal is sent even when the choice is not changed. If you need to know when the choice actually changes, use signal currentIndexChanged().

Referenced by setLineEdit().

◆ activated [2/2]

void QComboBox::activated ( const QString text)
signal

This signal is sent when the user chooses an item in the combobox.

The item's text is passed. Note that this signal is sent even when the choice is not changed. If you need to know when the choice actually changes, use signal currentIndexChanged().

◆ addItem() [1/2]

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

Adds an item to the combobox with the given text, and containing the specified userData (stored in the Qt::UserRole).

The item is appended to the list of existing items.

Definition at line 323 of file qcombobox.h.

Referenced by isc(), populatePaperSizes(), QBooleanComboBox::QBooleanComboBox(), QPPDOptionsEditor::setEditorData(), and QPrintDialogPrivate::setupOptions().

324 { insertItem(count(), atext, auserData); }
int count() const
void insertItem(int index, const QString &text, const QVariant &userData=QVariant())
Inserts the text and userData (stored in the Qt::UserRole) into the combobox at the given index...
Definition: qcombobox.h:329

◆ addItem() [2/2]

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

Adds an item to the combobox with the given icon and text, and containing the specified userData (stored in the Qt::UserRole).

The item is appended to the list of existing items.

Definition at line 325 of file qcombobox.h.

327 { insertItem(count(), aicon, atext, auserData); }
int count() const
void insertItem(int index, const QString &text, const QVariant &userData=QVariant())
Inserts the text and userData (stored in the Qt::UserRole) into the combobox at the given index...
Definition: qcombobox.h:329

◆ addItems()

void QComboBox::addItems ( const QStringList texts)
inline

Adds each of the strings in the given texts to the combobox.

Each item is appended to the list of existing items in turn.

Definition at line 195 of file qcombobox.h.

196  { insertItems(count(), texts); }
int count() const
void insertItems(int index, const QStringList &texts)
Inserts the strings from the list into the combobox as separate items, starting at the index specifie...
Definition: qcombobox.cpp:2269

◆ autoCompletion()

bool QComboBox::autoCompletion ( ) const

Referenced by setMaxCount().

◆ autoCompletionCaseSensitivity()

Qt::CaseSensitivity QComboBox::autoCompletionCaseSensitivity ( ) const

Referenced by setAutoCompletion().

◆ changeEvent()

void QComboBox::changeEvent ( QEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2814 of file qcombobox.cpp.

2815 {
2816  Q_D(QComboBox);
2817  switch (e->type()) {
2818  case QEvent::StyleChange:
2819  d->updateDelegate();
2820 #ifdef Q_WS_MAC
2821  case QEvent::MacSizeChange:
2822 #endif
2823  d->sizeHint = QSize(); // invalidate size hint
2824  d->minimumSizeHint = QSize();
2825  d->updateLayoutDirection();
2826  if (d->lineEdit)
2827  d->updateLineEditGeometry();
2828  d->setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem);
2829 
2830 #ifdef Q_WS_S60
2831  if (d->container) {
2833  initStyleOption(&opt);
2834 
2835  if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
2836  QRect screen = qt_TRect2QRect(static_cast<CEikAppUi*>(S60->appUi())->ClientRect());
2837 
2838  QRect listRect(style()->subControlRect(QStyle::CC_ComboBox, &opt,
2840  listRect.setHeight(qMin(screen.height(), screen.width()));
2841 
2842  if (screen.width() < screen.height()) {
2843  // in portait, menu should be positioned above softkeys
2844  listRect.moveBottom(screen.bottom());
2845  } else {
2846  TRect staConTopRect = TRect();
2847  AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect);
2848  listRect.setWidth(listRect.height());
2849  //by default popup is centered on screen in landscape
2850  listRect.moveCenter(screen.center());
2851  if (staConTopRect.IsEmpty() && AknLayoutUtils::CbaLocation() != AknLayoutUtils::EAknCbaLocationBottom) {
2852  // landscape without stacon, menu should be at the right
2853  (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
2854  listRect.setLeft(screen.left());
2855  }
2856  }
2857 
2858  d->container->setGeometry(listRect);
2859  }
2860  }
2861 #endif
2862 
2863  // ### need to update scrollers etc. as well here
2864  break;
2865  case QEvent::EnabledChange:
2866  if (!isEnabled())
2867  hidePopup();
2868  break;
2869  case QEvent::PaletteChange: {
2870  d->updateViewContainerPaletteAndOpacity();
2871  break;
2872  }
2873  case QEvent::FontChange:
2874  d->sizeHint = QSize(); // invalidate size hint
2875  d->viewContainer()->setFont(font());
2876  if (d->lineEdit)
2877  d->updateLineEditGeometry();
2878  break;
2879  default:
2880  break;
2881  }
2883 }
double d
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
void initStyleOption(QStyleOptionComboBox *option) const
Initialize option with the values from this QComboBox.
Definition: qcombobox.cpp:1141
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
const char * styleHint(const QFontDef &request)
bool isEnabled() const
Definition: qwidget.h:948
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QStyleOptionComboBox class is used to describe the parameter for drawing a combobox.
Definition: qstyleoption.h:796
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
Definition: qstyleoption.h:89
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
const QFont & font() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
virtual void hidePopup()
Hides the list of items in the combobox if it is currently visible and resets the internal state...
Definition: qcombobox.cpp:2685
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ clear

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.

Definition at line 2742 of file qcombobox.cpp.

2743 {
2744  Q_D(QComboBox);
2745  d->model->removeRows(0, d->model->rowCount(d->root), d->root);
2746 #ifndef QT_NO_ACCESSIBILITY
2748 #endif
2749 }
double d
Definition: qnumeric_p.h:62
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ clearEditText

void QComboBox::clearEditText ( )
slot

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

Definition at line 2763 of file qcombobox.cpp.

2764 {
2765  Q_D(QComboBox);
2766  if (d->lineEdit)
2767  d->lineEdit->clear();
2768 #ifndef QT_NO_ACCESSIBILITY
2770 #endif
2771 }
double d
Definition: qnumeric_p.h:62
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ completer()

QCompleter * QComboBox::completer ( ) const

Returns the completer that is used to auto complete text input for the combobox.

Since
4.2
See also
editable

Definition at line 1924 of file qcombobox.cpp.

1925 {
1926  Q_D(const QComboBox);
1927  return d->lineEdit ? d->lineEdit->completer() : 0;
1928 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ contextMenuEvent()

void QComboBox::contextMenuEvent ( QContextMenuEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3204 of file qcombobox.cpp.

3205 {
3206  Q_D(QComboBox);
3207  if (d->lineEdit) {
3208  Qt::ContextMenuPolicy p = d->lineEdit->contextMenuPolicy();
3209  d->lineEdit->setContextMenuPolicy(Qt::DefaultContextMenu);
3210  d->lineEdit->event(e);
3211  d->lineEdit->setContextMenuPolicy(p);
3212  }
3213 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
ContextMenuPolicy
Definition: qnamespace.h:1533
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ count()

int QComboBox::count ( ) const

◆ currentIndex()

int QComboBox::currentIndex ( ) const

◆ currentIndexChanged [1/2]

void QComboBox::currentIndexChanged ( int  index)
signal

This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically.

Since
4.1

The item's index is passed or -1 if the combobox becomes empty or the currentIndex was reset.

Referenced by QFontComboBox::QFontComboBox().

◆ currentIndexChanged [2/2]

void QComboBox::currentIndexChanged ( const QString text)
signal

This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically.

Since
4.1

The item's text is passed.

◆ currentText()

QString QComboBox::currentText ( ) const

◆ duplicatesEnabled()

bool QComboBox::duplicatesEnabled ( ) const

◆ editTextChanged

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.

Referenced by setLineEdit().

◆ event()

bool QComboBox::event ( QEvent event)
virtual

Reimplemented Function

Reimplemented from QWidget.

Reimplemented in QFontComboBox.

Definition at line 2940 of file qcombobox.cpp.

Referenced by QFontComboBox::event().

2941 {
2942  Q_D(QComboBox);
2943  switch(event->type()) {
2946  d->updateLayoutDirection();
2947  d->updateLineEditGeometry();
2948  break;
2949  case QEvent::HoverEnter:
2950  case QEvent::HoverLeave:
2951  case QEvent::HoverMove:
2952  if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
2953  d->updateHoverControl(he->pos());
2954  break;
2956  if (d->lineEdit)
2957  return d->lineEdit->event(event);
2958  break;
2959 #ifdef QT_KEYPAD_NAVIGATION
2960  case QEvent::EnterEditFocus:
2961  if (!d->lineEdit)
2962  setEditFocus(false); // We never want edit focus if we are not editable
2963  else
2964  d->lineEdit->event(event); //so cursor starts
2965  break;
2966  case QEvent::LeaveEditFocus:
2967  if (d->lineEdit)
2968  d->lineEdit->event(event); //so cursor stops
2969  break;
2970 #endif
2971  default:
2972  break;
2973  }
2974  return QWidget::event(event);
2975 }
double d
Definition: qnumeric_p.h:62
The QHoverEvent class contains parameters that describe a mouse event.
Definition: qevent.h:125
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ findData()

int QComboBox::findData ( const QVariant data,
int  role = Qt::UserRole,
Qt::MatchFlags  flags = static_cast<Qt::MatchFlags>(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.

Definition at line 1572 of file qcombobox.cpp.

Referenced by QPrintDialogPrivate::setPrinter().

1573 {
1574  Q_D(const QComboBox);
1575  QModelIndexList result;
1576  QModelIndex start = d->model->index(0, d->modelColumn, d->root);
1577  result = d->model->match(start, role, data, 1, flags);
1578  if (result.isEmpty())
1579  return -1;
1580  return result.first().row();
1581 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
int row() const
Returns the row this model index refers to.
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
The QModelIndex class is used to locate data in a data model.

◆ findText()

int QComboBox::findText ( const QString text,
Qt::MatchFlags  flags = static_cast<Qt::MatchFlags>(Qt::MatchExactly|Qt::MatchCaseSensitive) 
) const
inline

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

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

Definition at line 113 of file qcombobox.h.

Referenced by QInputDialogPrivate::setComboBoxText(), and QInputDialogPrivate::setListViewText().

115  { return findData(text, Qt::DisplayRole, flags); }
int findData(const QVariant &data, int role=Qt::UserRole, Qt::MatchFlags flags=static_cast< Qt::MatchFlags >(Qt::MatchExactly|Qt::MatchCaseSensitive)) const
Returns the index of the item containing the given data for the given role; otherwise returns -1...
Definition: qcombobox.cpp:1572

◆ focusInEvent()

void QComboBox::focusInEvent ( QFocusEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2789 of file qcombobox.cpp.

2790 {
2791  Q_D(QComboBox);
2792  update();
2793  if (d->lineEdit) {
2794  d->lineEdit->event(e);
2795 #ifndef QT_NO_COMPLETER
2796  if (d->lineEdit->completer())
2797  d->lineEdit->completer()->setWidget(this);
2798 #endif
2799  }
2800 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ focusOutEvent()

void QComboBox::focusOutEvent ( QFocusEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2805 of file qcombobox.cpp.

2806 {
2807  Q_D(QComboBox);
2808  update();
2809  if (d->lineEdit)
2810  d->lineEdit->event(e);
2811 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ hasFrame()

bool QComboBox::hasFrame ( ) const

Definition at line 3458 of file qcombobox.cpp.

3459 {
3460  Q_D(const QComboBox);
3461  return d->frame;
3462 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ hideEvent()

void QComboBox::hideEvent ( QHideEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2932 of file qcombobox.cpp.

2933 {
2934  hidePopup();
2935 }
virtual void hidePopup()
Hides the list of items in the combobox if it is currently visible and resets the internal state...
Definition: qcombobox.cpp:2685

◆ hidePopup()

void QComboBox::hidePopup ( )
virtual

Hides the list of items in the combobox if it is currently visible and resets the internal state, so that if the custom pop-up was shown inside the reimplemented showPopup(), then you also need to reimplement the hidePopup() function to hide your custom pop-up and call the base class implementation to reset the internal state whenever your custom pop-up widget is hidden.

See also
showPopup()

Definition at line 2685 of file qcombobox.cpp.

Referenced by changeEvent(), QAccessibleComboBox::doAction(), QComboBoxPrivateContainer::eventFilter(), hideEvent(), QComboBoxPrivateContainer::mousePressEvent(), and QComboBoxPrivateContainer::mouseReleaseEvent().

2686 {
2687  Q_D(QComboBox);
2688  if (d->container && d->container->isVisible()) {
2689 #if !defined(QT_NO_EFFECTS)
2690  d->model->blockSignals(true);
2691  d->container->itemView()->blockSignals(true);
2692  d->container->blockSignals(true);
2693  // Flash selected/triggered item (if any).
2695  QItemSelectionModel *selectionModel = view() ? view()->selectionModel() : 0;
2696  if (selectionModel && selectionModel->hasSelection()) {
2697  QEventLoop eventLoop;
2698  const QItemSelection selection = selectionModel->selection();
2699 
2700  // Deselect item and wait 60 ms.
2701  selectionModel->select(selection, QItemSelectionModel::Toggle);
2702  QTimer::singleShot(60, &eventLoop, SLOT(quit()));
2703  eventLoop.exec();
2704 
2705  // Select item and wait 20 ms.
2706  selectionModel->select(selection, QItemSelectionModel::Toggle);
2707  QTimer::singleShot(20, &eventLoop, SLOT(quit()));
2708  eventLoop.exec();
2709  }
2710  }
2711 
2712  // Fade out.
2713  bool needFade = style()->styleHint(QStyle::SH_Menu_FadeOutOnHide);
2714  if (needFade) {
2715 #if defined(Q_WS_MAC)
2716  macWindowFade(qt_mac_window_for(d->container));
2717 #endif // Q_WS_MAC
2718  // Other platform implementations welcome :-)
2719  }
2720  d->model->blockSignals(false);
2721  d->container->itemView()->blockSignals(false);
2722  d->container->blockSignals(false);
2723 
2724  if (!needFade)
2725 #endif // QT_NO_EFFECTS
2726  // Fade should implicitly hide as well ;-)
2727  d->container->hide();
2728  }
2729 #ifdef QT_KEYPAD_NAVIGATION
2730  if (QApplication::keypadNavigationEnabled() && isEditable() && hasFocus())
2731  setEditFocus(true);
2732 #endif
2733  d->_q_resetButton();
2734 }
double d
Definition: qnumeric_p.h:62
The QItemSelectionModel class keeps track of a view&#39;s selected items.
#define SLOT(a)
Definition: qobjectdefs.h:226
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
const QItemSelection selection() const
Returns the selection ranges stored in the selection model.
friend OSWindowRef qt_mac_window_for(const QWidget *w)
Definition: qwidget_mac.mm:484
bool hasFocus() const
Definition: qwidget.cpp:6583
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
The QEventLoop class provides a means of entering and leaving an event loop.
Definition: qeventloop.h:55
QItemSelectionModel * selectionModel() const
Returns the current selection model.
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
const char * styleHint(const QFontDef &request)
bool hasSelection() const
Returns true if the selection model contains any selection ranges; otherwise returns false...
The QItemSelection class manages information about selected items in a model.
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().
QAbstractItemView * view() const
Returns the list view used for the combobox popup.
Definition: qcombobox.cpp:2385
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59
bool isEditable() const
Definition: qcombobox.cpp:1723
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
Definition: qeventloop.cpp:181
void macWindowFade(void *window, float durationSeconds)

◆ highlighted [1/2]

void QComboBox::highlighted ( int  index)
signal

This signal is sent when an item in the combobox popup list is highlighted by the user.

The item's index is passed.

◆ highlighted [2/2]

void QComboBox::highlighted ( const QString text)
signal

This signal is sent when an item in the combobox popup list is highlighted by the user.

The item's text is passed.

◆ iconSize()

QSize QComboBox::iconSize ( ) const

◆ initStyleOption()

void QComboBox::initStyleOption ( QStyleOptionComboBox option) const
protected

Initialize option with the values from this QComboBox.

This method is useful for subclasses when they need a QStyleOptionComboBox, but don't want to fill in all the information themselves.

See also
QStyleOption::initFrom()

Definition at line 1141 of file qcombobox.cpp.

Referenced by changeEvent(), mousePressEvent(), paintEvent(), setEditable(), and showPopup().

1142 {
1143  if (!option)
1144  return;
1145 
1146  Q_D(const QComboBox);
1147  option->initFrom(this);
1148  option->editable = isEditable();
1149  option->frame = d->frame;
1150  if (hasFocus() && !option->editable)
1151  option->state |= QStyle::State_Selected;
1152  option->subControls = QStyle::SC_All;
1153  if (d->arrowState == QStyle::State_Sunken) {
1155  option->state |= d->arrowState;
1156  } else {
1157  option->activeSubControls = d->hoverControl;
1158  }
1159  if (d->currentIndex.isValid()) {
1160  option->currentText = currentText();
1161  option->currentIcon = d->itemIcon(d->currentIndex);
1162  }
1163  option->iconSize = iconSize();
1164  if (d->container && d->container->isVisible())
1165  option->state |= QStyle::State_On;
1166 }
double d
Definition: qnumeric_p.h:62
QSize iconSize
the icon size for the current item of the combo box
Definition: qstyleoption.h:807
QString currentText() const
bool frame
whether the combo box has a frame
Definition: qstyleoption.h:804
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
QString currentText
the text for the current item of the combo box
Definition: qstyleoption.h:805
QIcon currentIcon
the icon for the current item of the combo box
Definition: qstyleoption.h:806
QStyle::SubControls activeSubControls
This variable holds a bitwise OR of the sub-controls that are active for the complex control...
Definition: qstyleoption.h:694
bool editable
whether or not the combobox is editable or not
Definition: qstyleoption.h:802
bool hasFocus() const
Definition: qwidget.cpp:6583
#define Q_D(Class)
Definition: qglobal.h:2482
QSize iconSize() const
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
bool isEditable() const
Definition: qcombobox.cpp:1723
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
Definition: qstyleoption.h:693

◆ inputMethodEvent()

void QComboBox::inputMethodEvent ( QInputMethodEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3243 of file qcombobox.cpp.

3244 {
3245  Q_D(QComboBox);
3246  if (d->lineEdit) {
3247  d->lineEdit->event(e);
3248  } else {
3249  if (!e->commitString().isEmpty())
3250  d->keyboardSearchString(e->commitString());
3251  else
3252  e->ignore();
3253  }
3254 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
const QString & commitString() const
Returns the text that should get added to (or replace parts of) the text of the editor widget...
Definition: qevent.h:457
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310

◆ inputMethodQuery()

QVariant QComboBox::inputMethodQuery ( Qt::InputMethodQuery  query) const
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3259 of file qcombobox.cpp.

3260 {
3261  Q_D(const QComboBox);
3262  if (d->lineEdit)
3263  return d->lineEdit->inputMethodQuery(query);
3264  return QWidget::inputMethodQuery(query);
3265 }
double d
Definition: qnumeric_p.h:62
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition: qwidget.cpp:9683
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ insertItem() [1/2]

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

Inserts the text and userData (stored in the Qt::UserRole) into the combobox at the given index.

If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.

See also
insertItems()

Definition at line 329 of file qcombobox.h.

Referenced by insertSeparator().

331 { insertItem(aindex, QIcon(), atext, auserData); }
void insertItem(int index, const QString &text, const QVariant &userData=QVariant())
Inserts the text and userData (stored in the Qt::UserRole) into the combobox at the given index...
Definition: qcombobox.h:329
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ insertItem() [2/2]

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

Inserts the icon, text and userData (stored in the Qt::UserRole) into the combobox at the given index.

If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.

See also
insertItems()

Definition at line 2218 of file qcombobox.cpp.

2219 {
2220  Q_D(QComboBox);
2221  int itemCount = count();
2222  index = qBound(0, index, itemCount);
2223  if (index >= d->maxCount)
2224  return;
2225 
2226  // For the common case where we are using the built in QStandardItemModel
2227  // construct a QStandardItem, reducing the number of expensive signals from the model
2228  if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
2229  QStandardItem *item = new QStandardItem(text);
2230  if (!icon.isNull()) item->setData(icon, Qt::DecorationRole);
2231  if (userData.isValid()) item->setData(userData, Qt::UserRole);
2232  m->insertRow(index, item);
2233  ++itemCount;
2234  } else {
2235  d->inserting = true;
2236  if (d->model->insertRows(index, 1, d->root)) {
2237  QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2238  if (icon.isNull() && !userData.isValid()) {
2239  d->model->setData(item, text, Qt::EditRole);
2240  } else {
2242  if (!text.isNull()) values.insert(Qt::EditRole, text);
2243  if (!icon.isNull()) values.insert(Qt::DecorationRole, icon);
2244  if (userData.isValid()) values.insert(Qt::UserRole, userData);
2245  if (!values.isEmpty()) d->model->setItemData(item, values);
2246  }
2247  d->inserting = false;
2248  d->_q_rowsInserted(d->root, index, index);
2249  ++itemCount;
2250  } else {
2251  d->inserting = false;
2252  }
2253  }
2254 
2255  if (itemCount > d->maxCount)
2256  d->model->removeRows(itemCount - 1, itemCount - d->maxCount, d->root);
2257 }
double d
Definition: qnumeric_p.h:62
The QStandardItemModel class provides a generic model for storing custom data.
#define Q_D(Class)
Definition: qglobal.h:2482
int count() const
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
quint16 values[128]
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
The QModelIndex class is used to locate data in a data model.
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
Definition: qmap.h:203
quint16 index
The QStandardItem class provides an item for use with the QStandardItemModel class.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
virtual void setData(const QVariant &value, int role=Qt::UserRole+1)
Sets the item&#39;s data for the given role to the specified value.
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ insertItems()

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.

If the index is equal to or higher than the total number of items, the new items are appended to the list of existing items. If the index is zero or negative, the new items are prepended to the list of existing items.

See also
insertItem()

Definition at line 2269 of file qcombobox.cpp.

2270 {
2271  Q_D(QComboBox);
2272  if (list.isEmpty())
2273  return;
2274  index = qBound(0, index, count());
2275  int insertCount = qMin(d->maxCount - index, list.count());
2276  if (insertCount <= 0)
2277  return;
2278  // For the common case where we are using the built in QStandardItemModel
2279  // construct a QStandardItem, reducing the number of expensive signals from the model
2280  if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
2281  QList<QStandardItem *> items;
2282  QStandardItem *hiddenRoot = m->invisibleRootItem();
2283  for (int i = 0; i < insertCount; ++i)
2284  items.append(new QStandardItem(list.at(i)));
2285  hiddenRoot->insertRows(index, items);
2286  } else {
2287  d->inserting = true;
2288  if (d->model->insertRows(index, insertCount, d->root)) {
2289  QModelIndex item;
2290  for (int i = 0; i < insertCount; ++i) {
2291  item = d->model->index(i+index, d->modelColumn, d->root);
2292  d->model->setData(item, list.at(i), Qt::EditRole);
2293  }
2294  d->inserting = false;
2295  d->_q_rowsInserted(d->root, index, index + insertCount - 1);
2296  } else {
2297  d->inserting = false;
2298  }
2299  }
2300 
2301  int mc = count();
2302  if (mc > d->maxCount)
2303  d->model->removeRows(d->maxCount, mc - d->maxCount, d->root);
2304 }
double d
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QStandardItemModel class provides a generic model for storing custom data.
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
int count() const
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
The QModelIndex class is used to locate data in a data model.
quint16 index
The QStandardItem class provides an item for use with the QStandardItemModel class.
void insertRows(int row, const QList< QStandardItem *> &items)
Inserts items at row.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ insertPolicy()

InsertPolicy QComboBox::insertPolicy ( ) const

◆ insertSeparator()

void QComboBox::insertSeparator ( int  index)

Inserts a separator item into the combobox at the given index.

Since
4.4

If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.

See also
insertItem()

Definition at line 2320 of file qcombobox.cpp.

2321 {
2322  Q_D(QComboBox);
2323  int itemCount = count();
2324  index = qBound(0, index, itemCount);
2325  if (index >= d->maxCount)
2326  return;
2327  insertItem(index, QIcon(), QString());
2328  QComboBoxDelegate::setSeparator(d->model, d->model->index(index, 0, d->root));
2329 }
double d
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
int count() const
void insertItem(int index, const QString &text, const QVariant &userData=QVariant())
Inserts the text and userData (stored in the Qt::UserRole) into the combobox at the given index...
Definition: qcombobox.h:329
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
static void setSeparator(QAbstractItemModel *model, const QModelIndex &index)
Definition: qcombobox_p.h:304
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
quint16 index
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ isEditable()

bool QComboBox::isEditable ( ) const

Definition at line 1723 of file qcombobox.cpp.

Referenced by QInputDialogPrivate::chooseRightTextInputWidget(), QComboBoxPrivateContainer::comboStyleOption(), hidePopup(), initStyleOption(), QComboBoxPrivateContainer::mousePressEvent(), mousePressEvent(), QComboBoxListView::paintEvent(), setAutoCompletion(), QInputDialogPrivate::setComboBoxText(), and setEditable().

1724 {
1725  Q_D(const QComboBox);
1726  return d->lineEdit != 0;
1727 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ itemData()

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.

Definition at line 2182 of file qcombobox.cpp.

Referenced by QPrintDialogPrivate::_q_okClicked(), and QPrintDialogPrivate::_q_printRangeSelected().

2183 {
2184  Q_D(const QComboBox);
2185  QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2186  return d->model->data(mi, role);
2187 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
The QModelIndex class is used to locate data in a data model.
quint16 index

◆ itemDelegate()

QAbstractItemDelegate * QComboBox::itemDelegate ( ) const

Returns the item delegate used by the popup list view.

See also
setItemDelegate()

Definition at line 1937 of file qcombobox.cpp.

1938 {
1939  return view()->itemDelegate();
1940 }
QAbstractItemDelegate * itemDelegate() const
Returns the item delegate used by this view and model.
QAbstractItemView * view() const
Returns the list view used for the combobox popup.
Definition: qcombobox.cpp:2385

◆ itemIcon()

QIcon QComboBox::itemIcon ( int  index) const

Returns the icon for the given index in the combobox.

Definition at line 2171 of file qcombobox.cpp.

2172 {
2173  Q_D(const QComboBox);
2174  QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2175  return d->itemIcon(mi);
2176 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
The QModelIndex class is used to locate data in a data model.
quint16 index

◆ itemText()

QString QComboBox::itemText ( int  index) const

Returns the text for the given index in the combobox.

Definition at line 2161 of file qcombobox.cpp.

Referenced by QComboBoxPrivate::_q_editingFinished(), QComboBoxPrivate::_q_emitCurrentIndexChanged(), QComboBoxPrivate::_q_emitHighlighted(), QComboBoxPrivate::emitActivated(), and QInputDialogPrivate::listViewText().

2162 {
2163  Q_D(const QComboBox);
2164  QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2165  return d->itemText(mi);
2166 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
The QModelIndex class is used to locate data in a data model.
quint16 index

◆ keyPressEvent()

void QComboBox::keyPressEvent ( QKeyEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3027 of file qcombobox.cpp.

3028 {
3029  Q_D(QComboBox);
3030 
3031 #ifndef QT_NO_COMPLETER
3032  if (d->lineEdit
3033  && d->lineEdit->completer()
3034  && d->lineEdit->completer()->popup()
3035  && d->lineEdit->completer()->popup()->isVisible()) {
3036  // provide same autocompletion support as line edit
3037  d->lineEdit->event(e);
3038  return;
3039  }
3040 #endif
3041 
3042  enum Move { NoMove=0 , MoveUp , MoveDown , MoveFirst , MoveLast};
3043 
3044  Move move = NoMove;
3045  int newIndex = currentIndex();
3046  switch (e->key()) {
3047  case Qt::Key_Up:
3048  if (e->modifiers() & Qt::ControlModifier)
3049  break; // pass to line edit for auto completion
3050  case Qt::Key_PageUp:
3051 #ifdef QT_KEYPAD_NAVIGATION
3052  if (QApplication::keypadNavigationEnabled())
3053  e->ignore();
3054  else
3055 #endif
3056  move = MoveUp;
3057  break;
3058  case Qt::Key_Down:
3059  if (e->modifiers() & Qt::AltModifier) {
3060  showPopup();
3061  return;
3062  } else if (e->modifiers() & Qt::ControlModifier)
3063  break; // pass to line edit for auto completion
3064  // fall through
3065  case Qt::Key_PageDown:
3066 #ifdef QT_KEYPAD_NAVIGATION
3067  if (QApplication::keypadNavigationEnabled())
3068  e->ignore();
3069  else
3070 #endif
3071  move = MoveDown;
3072  break;
3073  case Qt::Key_Home:
3074  if (!d->lineEdit)
3075  move = MoveFirst;
3076  break;
3077  case Qt::Key_End:
3078  if (!d->lineEdit)
3079  move = MoveLast;
3080  break;
3081  case Qt::Key_F4:
3082  if (!e->modifiers()) {
3083  showPopup();
3084  return;
3085  }
3086  break;
3087  case Qt::Key_Space:
3088  if (!d->lineEdit) {
3089  showPopup();
3090  return;
3091  }
3092  case Qt::Key_Enter:
3093  case Qt::Key_Return:
3094  case Qt::Key_Escape:
3095  if (!d->lineEdit)
3096  e->ignore();
3097  break;
3098 #ifdef QT_KEYPAD_NAVIGATION
3099  case Qt::Key_Select:
3100  if (QApplication::keypadNavigationEnabled()
3101  && (!hasEditFocus() || !d->lineEdit)) {
3102  showPopup();
3103  return;
3104  }
3105  break;
3106  case Qt::Key_Left:
3107  case Qt::Key_Right:
3108  if (QApplication::keypadNavigationEnabled() && !hasEditFocus())
3109  e->ignore();
3110  break;
3111  case Qt::Key_Back:
3112  if (QApplication::keypadNavigationEnabled()) {
3113  if (!hasEditFocus() || !d->lineEdit)
3114  e->ignore();
3115  } else {
3116  e->ignore(); // let the surounding dialog have it
3117  }
3118  break;
3119 #endif
3120  default:
3121  if (!d->lineEdit) {
3122  if (!e->text().isEmpty())
3123  d->keyboardSearchString(e->text());
3124  else
3125  e->ignore();
3126  }
3127  }
3128 
3129  if (move != NoMove) {
3130  e->accept();
3131  switch (move) {
3132  case MoveFirst:
3133  newIndex = -1;
3134  case MoveDown:
3135  newIndex++;
3136  while ((newIndex < count()) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
3137  newIndex++;
3138  break;
3139  case MoveLast:
3140  newIndex = count();
3141  case MoveUp:
3142  newIndex--;
3143  while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
3144  newIndex--;
3145  break;
3146  default:
3147  e->ignore();
3148  break;
3149  }
3150 
3151  if (newIndex >= 0 && newIndex < count() && newIndex != currentIndex()) {
3152  setCurrentIndex(newIndex);
3153  d->emitActivated(d->currentIndex);
3154  }
3155  } else if (d->lineEdit) {
3156  d->lineEdit->event(e);
3157  }
3158 }
double d
Definition: qnumeric_p.h:62
void setCurrentIndex(int index)
Definition: qcombobox.cpp:2102
#define Q_D(Class)
Definition: qglobal.h:2482
int count() const
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
virtual void showPopup()
Displays the list of items in the combobox.
Definition: qcombobox.cpp:2447
int currentIndex() const
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
void move(int x, int y)
This corresponds to move(QPoint(x, y)).
Definition: qwidget.h:1011

◆ keyReleaseEvent()

void QComboBox::keyReleaseEvent ( QKeyEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3164 of file qcombobox.cpp.

3165 {
3166  Q_D(QComboBox);
3167  if (d->lineEdit)
3168  d->lineEdit->event(e);
3169 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ lineEdit()

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.

Definition at line 1858 of file qcombobox.cpp.

Referenced by QComboBoxPrivate::_q_dataChanged(), QComboBoxPrivate::_q_editingFinished(), QComboBoxPrivate::_q_itemSelected(), QComboBoxPrivate::_q_returnPressed(), QComboBoxPrivate::_q_rowsRemoved(), QComboBoxPrivate::matchFlags(), QAccessibleComboBox::rect(), QComboBoxPrivate::setCurrentIndex(), QAccessibleComboBox::text(), QComboBoxPrivate::updateLineEditGeometry(), and QComboBoxPrivate::updateViewContainerPaletteAndOpacity().

1859 {
1860  Q_D(const QComboBox);
1861  return d->lineEdit;
1862 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ maxCount()

int QComboBox::maxCount ( ) const

◆ maxVisibleItems()

int QComboBox::maxVisibleItems ( ) const

Referenced by ~QComboBox().

◆ minimumContentsLength()

int QComboBox::minimumContentsLength ( ) const

Referenced by setSizeAdjustPolicy().

◆ minimumSizeHint()

QSize QComboBox::minimumSizeHint ( ) const
virtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2416 of file qcombobox.cpp.

2417 {
2418  Q_D(const QComboBox);
2419  return d->recomputeSizeHint(d->minimumSizeHint);
2420 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ model()

QAbstractItemModel * QComboBox::model ( ) const

Returns the model used by the combobox.

Definition at line 1968 of file qcombobox.cpp.

Referenced by QInputDialogPrivate::_q_currentRowChanged(), QInputDialogPrivate::ensureListView(), QComboBoxPrivate::itemIcon(), QComboBoxPrivate::itemText(), QComboBoxPrivate::setCurrentIndex(), QInputDialogPrivate::setListViewText(), setModel(), and QComboBoxPrivate::viewContainer().

1969 {
1970  Q_D(const QComboBox);
1972  QComboBox *that = const_cast<QComboBox*>(this);
1973  that->setModel(new QStandardItemModel(0, 1, that));
1974  }
1975  return d->model;
1976 }
double d
Definition: qnumeric_p.h:62
static QAbstractItemModel * staticEmptyModel()
The QStandardItemModel class provides a generic model for storing custom data.
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
void setModel(QAbstractItemModel *model)
Sets the model to be model.
Definition: qcombobox.cpp:1984

◆ modelColumn()

int QComboBox::modelColumn ( ) const

◆ mousePressEvent()

void QComboBox::mousePressEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2980 of file qcombobox.cpp.

2981 {
2982  Q_D(QComboBox);
2984  initStyleOption(&opt);
2986  this);
2987  if (e->button() == Qt::LeftButton && (sc == QStyle::SC_ComboBoxArrow || !isEditable())
2988  && !d->viewContainer()->isVisible()) {
2989  if (sc == QStyle::SC_ComboBoxArrow)
2990  d->updateArrow(QStyle::State_Sunken);
2991 #ifdef QT_KEYPAD_NAVIGATION
2992  //if the container already exists, then d->viewContainer() is safe to call
2993  if (d->container) {
2994 #endif
2995  // We've restricted the next couple of lines, because by not calling
2996  // viewContainer(), we avoid creating the QComboBoxPrivateContainer.
2997  d->viewContainer()->blockMouseReleaseTimer.start(QApplication::doubleClickInterval());
2998  d->viewContainer()->initialClickPosition = mapToGlobal(e->pos());
2999 #ifdef QT_KEYPAD_NAVIGATION
3000  }
3001 #endif
3002  showPopup();
3003  } else {
3004 #ifdef QT_KEYPAD_NAVIGATION
3005  if (QApplication::keypadNavigationEnabled() && sc == QStyle::SC_ComboBoxEditField && d->lineEdit) {
3006  d->lineEdit->event(e); //so lineedit can move cursor, etc
3007  return;
3008  }
3009 #endif
3011  }
3012 }
double d
Definition: qnumeric_p.h:62
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
virtual void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition: qwidget.cpp:9261
void initStyleOption(QStyleOptionComboBox *option) const
Initialize option with the values from this QComboBox.
Definition: qcombobox.cpp:1141
#define Q_D(Class)
Definition: qglobal.h:2482
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
QStyle * style() const
Definition: qwidget.cpp:2742
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
virtual void showPopup()
Displays the list of items in the combobox.
Definition: qcombobox.cpp:2447
The QStyleOptionComboBox class is used to describe the parameter for drawing a combobox.
Definition: qstyleoption.h:796
virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget=0) const =0
Returns the sub control at the given position in the given complex control (with the style options sp...
bool isEditable() const
Definition: qcombobox.cpp:1723
static int doubleClickInterval()
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.

◆ mouseReleaseEvent()

void QComboBox::mouseReleaseEvent ( QMouseEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3017 of file qcombobox.cpp.

3018 {
3019  Q_D(QComboBox);
3020  Q_UNUSED(e);
3021  d->updateArrow(QStyle::State_None);
3022 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ paintEvent()

void QComboBox::paintEvent ( QPaintEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2901 of file qcombobox.cpp.

2902 {
2903  QStylePainter painter(this);
2904  painter.setPen(palette().color(QPalette::Text));
2905 
2906  // draw the combobox frame, focusrect and selected etc.
2908  initStyleOption(&opt);
2909  painter.drawComplexControl(QStyle::CC_ComboBox, opt);
2910 
2911  // draw the icon and text
2912  painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
2913 }
void initStyleOption(QStyleOptionComboBox *option) const
Initialize option with the values from this QComboBox.
Definition: qcombobox.cpp:1141
const QPalette & palette() const
The QStyleOptionComboBox class is used to describe the parameter for drawing a combobox.
Definition: qstyleoption.h:796
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget...
Definition: qstylepainter.h:55

◆ removeItem()

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.

This function does nothing if index is out of range.

Definition at line 2337 of file qcombobox.cpp.

Referenced by QPrintDialogPrivate::setPrinter().

2338 {
2339  Q_D(QComboBox);
2340  if (index < 0 || index >= count())
2341  return;
2342  d->model->removeRows(index, 1, d->root);
2343 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
int count() const
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
quint16 index

◆ resizeEvent()

void QComboBox::resizeEvent ( QResizeEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2888 of file qcombobox.cpp.

2889 {
2890  Q_D(QComboBox);
2891 #ifdef Q_WS_S60
2892  if (d->viewContainer() && d->viewContainer()->isVisible())
2893  showPopup();
2894 #endif
2895  d->updateLineEditGeometry();
2896 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
virtual void showPopup()
Displays the list of items in the combobox.
Definition: qcombobox.cpp:2447

◆ rootModelIndex()

QModelIndex QComboBox::rootModelIndex ( ) const

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

See also
setRootModelIndex()

Definition at line 2065 of file qcombobox.cpp.

2066 {
2067  Q_D(const QComboBox);
2068  return QModelIndex(d->root);
2069 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
The QModelIndex class is used to locate data in a data model.

◆ setAutoCompletion()

void QComboBox::setAutoCompletion ( bool  enable)

Use setCompleter() instead.

Definition at line 1457 of file qcombobox.cpp.

Referenced by setLineEdit().

1458 {
1459  Q_D(QComboBox);
1460 
1461 #ifdef QT_KEYPAD_NAVIGATION
1462  if (QApplication::keypadNavigationEnabled() && !enable && isEditable())
1463  qWarning("QComboBox::setAutoCompletion: auto completion is mandatory when combo box editable");
1464 #endif
1465 
1466  d->autoCompletion = enable;
1467  if (!d->lineEdit)
1468  return;
1469  if (enable) {
1470  if (d->lineEdit->completer())
1471  return;
1472  d->completer = new QCompleter(d->model, d->lineEdit);
1473  d->completer->setCaseSensitivity(d->autoCompletionCaseSensitivity);
1474  d->completer->setCompletionMode(QCompleter::InlineCompletion);
1475  d->completer->setCompletionColumn(d->modelColumn);
1476  d->lineEdit->setCompleter(d->completer);
1477  d->completer->setWidget(this);
1478  } else {
1479  d->lineEdit->setCompleter(0);
1480  }
1481 }
double d
Definition: qnumeric_p.h:62
The QCompleter class provides completions based on an item model.
Definition: qcompleter.h:64
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
Q_CORE_EXPORT void qWarning(const char *,...)
bool isEditable() const
Definition: qcombobox.cpp:1723

◆ setAutoCompletionCaseSensitivity()

void QComboBox::setAutoCompletionCaseSensitivity ( Qt::CaseSensitivity  sensitivity)

Use setCompleter() and QCompleter::setCaseSensitivity() instead.

Definition at line 1521 of file qcombobox.cpp.

1522 {
1523  Q_D(QComboBox);
1524  d->autoCompletionCaseSensitivity = sensitivity;
1525  if (d->lineEdit && d->lineEdit->completer())
1526  d->lineEdit->completer()->setCaseSensitivity(sensitivity);
1527 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ setCompleter()

void QComboBox::setCompleter ( QCompleter completer)
Since
4.2

Sets the completer to use instead of the current completer. If completer is 0, auto completion is disabled.

By default, for an editable combo box, a QCompleter that performs case insensitive inline completion is automatically created.

Definition at line 1903 of file qcombobox.cpp.

1904 {
1905  Q_D(QComboBox);
1906  if (!d->lineEdit)
1907  return;
1908  d->lineEdit->setCompleter(c);
1909  if (c)
1910  c->setWidget(this);
1911 }
double d
Definition: qnumeric_p.h:62
unsigned char c[8]
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ setCurrentIndex

void QComboBox::setCurrentIndex ( int  index)
slot

Definition at line 2102 of file qcombobox.cpp.

Referenced by QComboBoxPrivate::_q_itemSelected(), QComboBoxPrivate::keyboardSearchString(), keyPressEvent(), QInputDialogPrivate::setComboBoxText(), QPPDOptionsEditor::setEditorData(), setModel(), setModelColumn(), QPrintDialogPrivate::setPrinter(), QBooleanComboBox::setValue(), and wheelEvent().

2103 {
2104  Q_D(QComboBox);
2105  QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
2106  d->setCurrentIndex(mi);
2107 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
The QModelIndex class is used to locate data in a data model.
quint16 index

◆ setDuplicatesEnabled()

void QComboBox::setDuplicatesEnabled ( bool  enable)

Definition at line 1549 of file qcombobox.cpp.

1550 {
1551  Q_D(QComboBox);
1552  d->duplicatesEnabled = enable;
1553 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ setEditable()

void QComboBox::setEditable ( bool  editable)

Definition at line 1759 of file qcombobox.cpp.

Referenced by QPrintPreviewDialogPrivate::init(), QComboBox(), and QFontComboBox::QFontComboBox().

1760 {
1761  Q_D(QComboBox);
1762  if (isEditable() == editable)
1763  return;
1764 
1765  d->updateDelegate();
1766 
1768  initStyleOption(&opt);
1769  if (editable) {
1770  if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
1771  d->viewContainer()->updateScrollers();
1773  }
1774  QLineEdit *le = new QLineEdit(this);
1775  setLineEdit(le);
1776  } else {
1777  if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
1778  d->viewContainer()->updateScrollers();
1780  }
1782  d->lineEdit->hide();
1783  d->lineEdit->deleteLater();
1784  d->lineEdit = 0;
1785  }
1786 
1787  d->viewContainer()->updateTopBottomMargin();
1789  adjustSize();
1790 }
double d
Definition: qnumeric_p.h:62
void initStyleOption(QStyleOptionComboBox *option) const
Initialize option with the values from this QComboBox.
Definition: qcombobox.cpp:1141
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
bool editable
whether the combo box can be edited by the user
Definition: qcombobox.h:68
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
void adjustSize()
Adjusts the size of the widget to fit its contents.
Definition: qwidget.cpp:8488
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
const char * styleHint(const QFontDef &request)
void setLineEdit(QLineEdit *edit)
Sets the line edit to use instead of the current line edit widget.
Definition: qcombobox.cpp:1797
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy)
QAbstractItemView * view() const
Returns the list view used for the combobox popup.
Definition: qcombobox.cpp:2385
The QStyleOptionComboBox class is used to describe the parameter for drawing a combobox.
Definition: qstyleoption.h:796
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
bool isEditable() const
Definition: qcombobox.cpp:1723

◆ setEditText

void QComboBox::setEditText ( const QString text)
slot

Sets the text in the combobox's text edit.

Definition at line 2776 of file qcombobox.cpp.

Referenced by QInputDialogPrivate::setComboBoxText().

2777 {
2778  Q_D(QComboBox);
2779  if (d->lineEdit)
2780  d->lineEdit->setText(text);
2781 #ifndef QT_NO_ACCESSIBILITY
2783 #endif
2784 }
double d
Definition: qnumeric_p.h:62
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ setFrame()

void QComboBox::setFrame ( bool  enable)

Definition at line 3465 of file qcombobox.cpp.

Referenced by QDefaultItemEditorFactory::createEditor().

3466 {
3467  Q_D(QComboBox);
3468  d->frame = enable;
3469  update();
3470  updateGeometry();
3471 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372

◆ setIconSize()

void QComboBox::setIconSize ( const QSize size)

Definition at line 1699 of file qcombobox.cpp.

1700 {
1701  Q_D(QComboBox);
1702  if (size == d->iconSize)
1703  return;
1704 
1705  view()->setIconSize(size);
1706  d->iconSize = size;
1707  d->sizeHint = QSize();
1708  updateGeometry();
1709 }
double d
Definition: qnumeric_p.h:62
QSize size() const
void setIconSize(const QSize &size)
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
QAbstractItemView * view() const
Returns the list view used for the combobox popup.
Definition: qcombobox.cpp:2385
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372

◆ setInsertPolicy()

void QComboBox::setInsertPolicy ( InsertPolicy  policy)

Definition at line 1603 of file qcombobox.cpp.

1604 {
1605  Q_D(QComboBox);
1606  d->insertPolicy = policy;
1607 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ setItemData()

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.

Definition at line 2373 of file qcombobox.cpp.

2374 {
2375  Q_D(const QComboBox);
2376  QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2377  if (item.isValid()) {
2378  d->model->setData(item, value, role);
2379  }
2380 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QModelIndex class is used to locate data in a data model.
quint16 index

◆ setItemDelegate()

void QComboBox::setItemDelegate ( QAbstractItemDelegate delegate)

Sets the item delegate for the popup list view.

The combobox takes ownership of the delegate.

Warning
You should not share the same instance of a delegate between comboboxes, widget mappers or views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive the QAbstractItemDelegate::closeEditor() signal, and attempt to access, modify or close an editor that has already been closed.
See also
itemDelegate()

Definition at line 1954 of file qcombobox.cpp.

Referenced by QFontComboBox::QFontComboBox().

1955 {
1956  if (!delegate) {
1957  qWarning("QComboBox::setItemDelegate: cannot set a 0 delegate");
1958  return;
1959  }
1960  delete view()->itemDelegate();
1961  view()->setItemDelegate(delegate);
1962 }
QAbstractItemDelegate * itemDelegate() const
Returns the item delegate used by this view and model.
Q_CORE_EXPORT void qWarning(const char *,...)
QAbstractItemView * view() const
Returns the list view used for the combobox popup.
Definition: qcombobox.cpp:2385
void setItemDelegate(QAbstractItemDelegate *delegate)
Sets the item delegate for this view and its model to delegate.

◆ setItemIcon()

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

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

Definition at line 2360 of file qcombobox.cpp.

2361 {
2362  Q_D(const QComboBox);
2363  QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2364  if (item.isValid()) {
2365  d->model->setData(item, icon, Qt::DecorationRole);
2366  }
2367 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QModelIndex class is used to locate data in a data model.
quint16 index

◆ setItemText()

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

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

Definition at line 2348 of file qcombobox.cpp.

2349 {
2350  Q_D(const QComboBox);
2351  QModelIndex item = d->model->index(index, d->modelColumn, d->root);
2352  if (item.isValid()) {
2353  d->model->setData(item, text, Qt::EditRole);
2354  }
2355 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QModelIndex class is used to locate data in a data model.
quint16 index

◆ setLineEdit()

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.

Definition at line 1797 of file qcombobox.cpp.

Referenced by setEditable().

1798 {
1799  Q_D(QComboBox);
1800  if (!edit) {
1801  qWarning("QComboBox::setLineEdit: cannot set a 0 line edit");
1802  return;
1803  }
1804 
1805  if (edit == d->lineEdit)
1806  return;
1807 
1808  edit->setText(currentText());
1809  delete d->lineEdit;
1810 
1811  d->lineEdit = edit;
1812  if (d->lineEdit->parent() != this)
1813  d->lineEdit->setParent(this);
1814  connect(d->lineEdit, SIGNAL(returnPressed()), this, SLOT(_q_returnPressed()));
1815  connect(d->lineEdit, SIGNAL(editingFinished()), this, SLOT(_q_editingFinished()));
1816  connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(editTextChanged(QString)));
1817 #ifdef QT3_SUPPORT
1818  connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString)));
1819 #endif
1820  d->lineEdit->setFrame(false);
1821  d->lineEdit->setContextMenuPolicy(Qt::NoContextMenu);
1822  d->lineEdit->setFocusProxy(this);
1823  d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
1824 #ifndef QT_NO_COMPLETER
1825  setAutoCompletion(d->autoCompletion);
1826 #endif
1827 
1828 #ifdef QT_KEYPAD_NAVIGATION
1829 #ifndef QT_NO_COMPLETER
1830  if (QApplication::keypadNavigationEnabled()) {
1831  // Editable combo boxes will have a completer that is set to UnfilteredPopupCompletion.
1832  // This means that when the user enters edit mode they are immediately presented with a
1833  // list of possible completions.
1834  setAutoCompletion(true);
1835  if (d->completer) {
1836  d->completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
1837  connect(d->completer, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated()));
1838  }
1839  }
1840 #endif
1841 #endif
1842 
1844  d->updateLayoutDirection();
1845  d->updateLineEditGeometry();
1846  if (isVisible())
1847  d->lineEdit->show();
1848 
1849  update();
1850 }
double d
Definition: qnumeric_p.h:62
QString currentText() const
bool isVisible() const
Definition: qwidget.h:1005
#define SLOT(a)
Definition: qobjectdefs.h:226
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
void activated(int index)
This signal is sent when the user chooses an item in the combobox.
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
Q_CORE_EXPORT void qWarning(const char *,...)
void editTextChanged(const QString &)
This signal is emitted when the text in the combobox&#39;s line edit widget is changed.
void setText(const QString &)
Definition: qlineedit.cpp:401
void setAutoCompletion(bool enable)
Use setCompleter() instead.
Definition: qcombobox.cpp:1457
The QModelIndex class is used to locate data in a data model.
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087

◆ setMaxCount()

void QComboBox::setMaxCount ( int  max)

Definition at line 1397 of file qcombobox.cpp.

1398 {
1399  Q_D(QComboBox);
1400  if (max < 0) {
1401  qWarning("QComboBox::setMaxCount: Invalid count (%d) must be >= 0", max);
1402  return;
1403  }
1404 
1405  if (max < count())
1406  d->model->removeRows(max, count() - max, d->root);
1407 
1408  d->maxCount = max;
1409 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
int count() const
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setMaxVisibleItems()

void QComboBox::setMaxVisibleItems ( int  maxItems)

Definition at line 1356 of file qcombobox.cpp.

1357 {
1358  Q_D(QComboBox);
1359  if (maxItems < 0) {
1360  qWarning("QComboBox::setMaxVisibleItems: "
1361  "Invalid max visible items (%d) must be >= 0", maxItems);
1362  return;
1363  }
1364  d->maxVisibleItems = maxItems;
1365 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setMinimumContentsLength()

void QComboBox::setMinimumContentsLength ( int  characters)

Definition at line 1660 of file qcombobox.cpp.

1661 {
1662  Q_D(QComboBox);
1663  if (characters == d->minimumContentsLength || characters < 0)
1664  return;
1665 
1666  d->minimumContentsLength = characters;
1667 
1668  if (d->sizeAdjustPolicy == AdjustToContents
1669  || d->sizeAdjustPolicy == AdjustToMinimumContentsLength
1670  || d->sizeAdjustPolicy == AdjustToMinimumContentsLengthWithIcon) {
1671  d->sizeHint = QSize();
1672  d->adjustComboBoxSize();
1673  updateGeometry();
1674  }
1675 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372

◆ setModel()

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

Definition at line 1984 of file qcombobox.cpp.

Referenced by model(), and QFontComboBox::QFontComboBox().

1985 {
1986  Q_D(QComboBox);
1987 
1988  if (!model) {
1989  qWarning("QComboBox::setModel: cannot set a 0 model");
1990  return;
1991  }
1992 
1993 #ifndef QT_NO_COMPLETER
1994  if (d->lineEdit && d->lineEdit->completer()
1995  && d->lineEdit->completer() == d->completer)
1996  d->lineEdit->completer()->setModel(model);
1997 #endif
1998  if (d->model) {
1999  disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
2000  this, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));
2001  disconnect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
2002  this, SLOT(_q_updateIndexBeforeChange()));
2003  disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
2004  this, SLOT(_q_rowsInserted(QModelIndex,int,int)));
2005  disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
2006  this, SLOT(_q_updateIndexBeforeChange()));
2007  disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
2008  this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
2009  disconnect(d->model, SIGNAL(destroyed()),
2010  this, SLOT(_q_modelDestroyed()));
2011  disconnect(d->model, SIGNAL(modelAboutToBeReset()),
2012  this, SLOT(_q_updateIndexBeforeChange()));
2013  disconnect(d->model, SIGNAL(modelReset()),
2014  this, SLOT(_q_modelReset()));
2015  if (d->model->QObject::parent() == this)
2016  delete d->model;
2017  }
2018 
2019  d->model = model;
2020 
2021  connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
2022  this, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));
2023  connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
2024  this, SLOT(_q_updateIndexBeforeChange()));
2025  connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
2026  this, SLOT(_q_rowsInserted(QModelIndex,int,int)));
2027  connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
2028  this, SLOT(_q_updateIndexBeforeChange()));
2029  connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
2030  this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
2031  connect(model, SIGNAL(destroyed()),
2032  this, SLOT(_q_modelDestroyed()));
2033  connect(model, SIGNAL(modelAboutToBeReset()),
2034  this, SLOT(_q_updateIndexBeforeChange()));
2035  connect(model, SIGNAL(modelReset()),
2036  this, SLOT(_q_modelReset()));
2037 
2038  if (d->container)
2039  d->container->itemView()->setModel(model);
2040 
2041  bool currentReset = false;
2042 
2043  if (count()) {
2044  for (int pos=0; pos < count(); pos++) {
2045  if (d->model->index(pos, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled) {
2047  currentReset = true;
2048  break;
2049  }
2050  }
2051  }
2052 
2053  if (!currentReset)
2054  setCurrentIndex(-1);
2055 
2056  d->modelChanged();
2057 }
QPoint pos() const
double d
Definition: qnumeric_p.h:62
#define SLOT(a)
Definition: qobjectdefs.h:226
void setCurrentIndex(int index)
Definition: qcombobox.cpp:2102
#define Q_D(Class)
Definition: qglobal.h:2482
int count() const
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
Q_CORE_EXPORT void qWarning(const char *,...)
QAbstractItemModel * model() const
Returns the model used by the combobox.
Definition: qcombobox.cpp:1968
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
The QModelIndex class is used to locate data in a data model.

◆ setModelColumn()

void QComboBox::setModelColumn ( int  visibleColumn)

Definition at line 3492 of file qcombobox.cpp.

3493 {
3494  Q_D(QComboBox);
3495  d->modelColumn = visibleColumn;
3496  QListView *lv = qobject_cast<QListView *>(d->viewContainer()->itemView());
3497  if (lv)
3498  lv->setModelColumn(visibleColumn);
3499 #ifndef QT_NO_COMPLETER
3500  if (d->lineEdit && d->lineEdit->completer()
3501  && d->lineEdit->completer() == d->completer)
3502  d->lineEdit->completer()->setCompletionColumn(visibleColumn);
3503 #endif
3504  setCurrentIndex(currentIndex()); //update the text to the text of the new column;
3505 }
double d
Definition: qnumeric_p.h:62
void setCurrentIndex(int index)
Definition: qcombobox.cpp:2102
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
void setModelColumn(int column)
Definition: qlistview.cpp:1586
The QListView class provides a list or icon view onto a model.
Definition: qlistview.h:57
int currentIndex() const

◆ setRootModelIndex()

void QComboBox::setRootModelIndex ( const QModelIndex index)

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

See also
rootModelIndex()

Definition at line 2076 of file qcombobox.cpp.

2077 {
2078  Q_D(QComboBox);
2079  d->root = QPersistentModelIndex(index);
2080  view()->setRootIndex(index);
2081  update();
2082 }
double d
Definition: qnumeric_p.h:62
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
The QPersistentModelIndex class is used to locate data in a data model.
QAbstractItemView * view() const
Returns the list view used for the combobox popup.
Definition: qcombobox.cpp:2385

◆ setSizeAdjustPolicy()

void QComboBox::setSizeAdjustPolicy ( QComboBox::SizeAdjustPolicy  policy)

Definition at line 1628 of file qcombobox.cpp.

1629 {
1630  Q_D(QComboBox);
1631  if (policy == d->sizeAdjustPolicy)
1632  return;
1633 
1634  d->sizeAdjustPolicy = policy;
1635  d->sizeHint = QSize();
1636  d->adjustComboBoxSize();
1637  updateGeometry();
1638 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372

◆ setValidator()

void QComboBox::setValidator ( const QValidator v)

Sets the validator to use instead of the current validator.

Definition at line 1871 of file qcombobox.cpp.

1872 {
1873  Q_D(QComboBox);
1874  if (d->lineEdit)
1875  d->lineEdit->setValidator(v);
1876 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ setView()

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.

Definition at line 2400 of file qcombobox.cpp.

2401 {
2402  Q_D(QComboBox);
2403  if (!itemView) {
2404  qWarning("QComboBox::setView: cannot set a 0 view");
2405  return;
2406  }
2407 
2408  if (itemView->model() != d->model)
2409  itemView->setModel(d->model);
2410  d->viewContainer()->setItemView(itemView);
2411 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
Q_CORE_EXPORT void qWarning(const char *,...)
QAbstractItemModel * model() const
Returns the model that this view is presenting.

◆ showEvent()

void QComboBox::showEvent ( QShowEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 2918 of file qcombobox.cpp.

2919 {
2920  Q_D(QComboBox);
2921  if (!d->shownOnce && d->sizeAdjustPolicy == QComboBox::AdjustToContentsOnFirstShow) {
2922  d->sizeHint = QSize();
2923  updateGeometry();
2924  }
2925  d->shownOnce = true;
2926  QWidget::showEvent(e);
2927 }
double d
Definition: qnumeric_p.h:62
virtual void showEvent(QShowEvent *)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qwidget.cpp:9842
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372

◆ showPopup()

void QComboBox::showPopup ( )
virtual

Displays the list of items in the combobox.

If the list is empty then the no items will be shown.

If you reimplement this function to show a custom pop-up, make sure you call hidePopup() to reset the internal state.

See also
hidePopup()

Reimplemented in QFileDialogComboBox.

Definition at line 2447 of file qcombobox.cpp.

Referenced by QAccessibleComboBox::doAction(), keyPressEvent(), mousePressEvent(), resizeEvent(), and QFileDialogComboBox::showPopup().

2448 {
2449  Q_D(QComboBox);
2450  if (count() <= 0)
2451  return;
2452 
2453 #ifdef QT_KEYPAD_NAVIGATION
2454 #ifndef QT_NO_COMPLETER
2455  if (QApplication::keypadNavigationEnabled() && d->completer) {
2456  // editable combo box is line edit plus completer
2457  setEditFocus(true);
2458  d->completer->complete(); // show popup
2459  return;
2460  }
2461 #endif
2462 #endif
2463 
2464  QStyle * const style = this->style();
2465 
2466  // set current item and select it
2467  view()->selectionModel()->setCurrentIndex(d->currentIndex,
2469  QComboBoxPrivateContainer* container = d->viewContainer();
2471  initStyleOption(&opt);
2472  QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt,
2474 #ifndef Q_WS_S60
2475  QRect screen = d->popupGeometry(QApplication::desktop()->screenNumber(this));
2476 #else
2477  QRect screen = qt_TRect2QRect(static_cast<CEikAppUi*>(S60->appUi())->ClientRect());
2478 #endif
2479 
2480  QPoint below = mapToGlobal(listRect.bottomLeft());
2481  int belowHeight = screen.bottom() - below.y();
2482  QPoint above = mapToGlobal(listRect.topLeft());
2483  int aboveHeight = above.y() - screen.y();
2484  bool boundToScreen = !window()->testAttribute(Qt::WA_DontShowOnScreen);
2485 
2486  const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this);
2487  {
2488  int listHeight = 0;
2489  int count = 0;
2490  QStack<QModelIndex> toCheck;
2491  toCheck.push(view()->rootIndex());
2492 #ifndef QT_NO_TREEVIEW
2493  QTreeView *treeView = qobject_cast<QTreeView*>(view());
2494  if (treeView && treeView->header() && !treeView->header()->isHidden())
2495  listHeight += treeView->header()->height();
2496 #endif
2497  while (!toCheck.isEmpty()) {
2498  QModelIndex parent = toCheck.pop();
2499  for (int i = 0; i < d->model->rowCount(parent); ++i) {
2500  QModelIndex idx = d->model->index(i, d->modelColumn, parent);
2501  if (!idx.isValid())
2502  continue;
2503  listHeight += view()->visualRect(idx).height() + container->spacing();
2504 #ifndef QT_NO_TREEVIEW
2505  if (d->model->hasChildren(idx) && treeView && treeView->isExpanded(idx))
2506  toCheck.push(idx);
2507 #endif
2508  ++count;
2509  if (!usePopup && count >= d->maxVisibleItems) {
2510  toCheck.clear();
2511  break;
2512  }
2513  }
2514  }
2515  listRect.setHeight(listHeight);
2516  }
2517 
2518  {
2519  // add the spacing for the grid on the top and the bottom;
2520  int heightMargin = 2*container->spacing();
2521 
2522  // add the frame of the container
2523  int marginTop, marginBottom;
2524  container->getContentsMargins(0, &marginTop, 0, &marginBottom);
2525  heightMargin += marginTop + marginBottom;
2526 
2527  //add the frame of the view
2528  view()->getContentsMargins(0, &marginTop, 0, &marginBottom);
2529  marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top;
2530  marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom;
2531  heightMargin += marginTop + marginBottom;
2532 
2533  listRect.setHeight(listRect.height() + heightMargin);
2534  }
2535 
2536  // Add space for margin at top and bottom if the style wants it.
2537  if (usePopup)
2538  listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2);
2539 
2540  // Make sure the popup is wide enough to display its contents.
2541  if (usePopup) {
2542  const int diff = d->computeWidthHint() - width();
2543  if (diff > 0)
2544  listRect.setWidth(listRect.width() + diff);
2545  }
2546 
2547  //we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
2548  container->layout()->activate();
2549  //takes account of the minimum/maximum size of the container
2550  listRect.setSize( listRect.size().expandedTo(container->minimumSize())
2551  .boundedTo(container->maximumSize()));
2552 
2553  // make sure the widget fits on screen
2554  if (boundToScreen) {
2555  if (listRect.width() > screen.width() )
2556  listRect.setWidth(screen.width());
2557  if (mapToGlobal(listRect.bottomRight()).x() > screen.right()) {
2558  below.setX(screen.x() + screen.width() - listRect.width());
2559  above.setX(screen.x() + screen.width() - listRect.width());
2560  }
2561  if (mapToGlobal(listRect.topLeft()).x() < screen.x() ) {
2562  below.setX(screen.x());
2563  above.setX(screen.x());
2564  }
2565  }
2566 
2567  if (usePopup) {
2568  // Position horizontally.
2569  listRect.moveLeft(above.x());
2570 
2571 #ifndef Q_WS_S60
2572  // Position vertically so the curently selected item lines up
2573  // with the combo box.
2574  const QRect currentItemRect = view()->visualRect(view()->currentIndex());
2575  const int offset = listRect.top() - currentItemRect.top();
2576  listRect.moveTop(above.y() + offset - listRect.top());
2577 #endif
2578 
2579 
2580  // Clamp the listRect height and vertical position so we don't expand outside the
2581  // available screen geometry.This may override the vertical position, but it is more
2582  // important to show as much as possible of the popup.
2583  const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height());
2584  listRect.setHeight(height);
2585 
2586  if (boundToScreen) {
2587  if (listRect.top() < screen.top())
2588  listRect.moveTop(screen.top());
2589  if (listRect.bottom() > screen.bottom())
2590  listRect.moveBottom(screen.bottom());
2591  }
2592 #ifdef Q_WS_S60
2593  if (screen.width() < screen.height()) {
2594  // in portait, menu should be positioned above softkeys
2595  listRect.moveBottom(screen.bottom());
2596  } else {
2597  TRect staConTopRect = TRect();
2598  AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect);
2599  listRect.setWidth(screen.height());
2600  //by default popup is centered on screen in landscape
2601  listRect.moveCenter(screen.center());
2602  if (staConTopRect.IsEmpty() && AknLayoutUtils::CbaLocation() != AknLayoutUtils::EAknCbaLocationBottom) {
2603  // landscape without stacon, menu should be at the right
2604  (opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
2605  listRect.setLeft(screen.left());
2606  }
2607  }
2608 #endif
2609  } else if (!boundToScreen || listRect.height() <= belowHeight) {
2610  listRect.moveTopLeft(below);
2611  } else if (listRect.height() <= aboveHeight) {
2612  listRect.moveBottomLeft(above);
2613  } else if (belowHeight >= aboveHeight) {
2614  listRect.setHeight(belowHeight);
2615  listRect.moveTopLeft(below);
2616  } else {
2617  listRect.setHeight(aboveHeight);
2618  listRect.moveBottomLeft(above);
2619  }
2620 
2621 #ifndef QT_NO_IM
2622  if (QInputContext *qic = inputContext())
2623  qic->reset();
2624 #endif
2625  QScrollBar *sb = view()->horizontalScrollBar();
2627  bool needHorizontalScrollBar = (policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn)
2628  && sb->minimum() < sb->maximum();
2629  if (needHorizontalScrollBar) {
2630  listRect.adjust(0, 0, 0, sb->height());
2631  }
2632  container->setGeometry(listRect);
2633 
2634 #ifndef Q_WS_MAC
2635  const bool updatesEnabled = container->updatesEnabled();
2636 #endif
2637 
2638 #if defined(Q_WS_WIN) && !defined(QT_NO_EFFECTS)
2639  bool scrollDown = (listRect.topLeft() == below);
2642  qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150);
2643 #endif
2644 
2645 // Don't disable updates on Mac OS X. Windows are displayed immediately on this platform,
2646 // which means that the window will be visible before the call to container->show() returns.
2647 // If updates are disabled at this point we'll miss our chance at painting the popup
2648 // menu before it's shown, causing flicker since the window then displays the standard gray
2649 // background.
2650 #ifndef Q_WS_MAC
2651  container->setUpdatesEnabled(false);
2652 #endif
2653 
2654  container->raise();
2655  container->show();
2656  container->updateScrollers();
2657  view()->setFocus();
2658 
2659  view()->scrollTo(view()->currentIndex(),
2660  style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)
2663 
2664 #ifndef Q_WS_MAC
2665  container->setUpdatesEnabled(updatesEnabled);
2666 #endif
2667 
2668  container->update();
2669 #ifdef QT_KEYPAD_NAVIGATION
2670  if (QApplication::keypadNavigationEnabled())
2671  view()->setEditFocus(true);
2672 #endif
2673 }
double d
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
virtual QRect visualRect(const QModelIndex &index) const =0
Returns the rectangle on the viewport occupied by the item at index.
int minimum() const
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=0) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
bool activate()
Redoes the layout for parentWidget() if necessary.
Definition: qlayout.cpp:1249
bool updatesEnabled() const
Qt::ScrollBarPolicy horizontalScrollBarPolicy() const
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
void initStyleOption(QStyleOptionComboBox *option) const
Initialize option with the values from this QComboBox.
Definition: qcombobox.cpp:1141
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
bool isExpanded(const QModelIndex &index) const
Returns true if the model item index is expanded; otherwise returns false.
Definition: qtreeview.cpp:859
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
T * qobject_cast(QObject *object)
Definition: qobject.h:375
void setUpdatesEnabled(bool enable)
Definition: qwidget.cpp:7670
#define Q_D(Class)
Definition: qglobal.h:2482
int height() const
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
QStyle * style() const
Definition: qwidget.cpp:2742
int count() const
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
The QScrollBar widget provides a vertical or horizontal scroll bar.
Definition: qscrollbar.h:59
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Returns the widget&#39;s contents margins for left, top, right, and bottom.
Definition: qwidget.cpp:7509
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
void qScrollEffect(QWidget *w, QEffects::DirFlags orient, int time)
Scroll widget w in time ms.
Definition: qeffects.cpp:562
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
void raise()
Raises this widget to the top of the parent widget&#39;s stack.
Definition: qwidget.cpp:11901
QItemSelectionModel * selectionModel() const
Returns the current selection model.
virtual void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)=0
Scrolls the view if necessary to ensure that the item at index is visible.
int width() const
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
static Bigint * diff(Bigint *a, Bigint *b)
void show()
Shows the widget and its child widgets.
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QInputContext * inputContext()
This function returns the QInputContext for this widget.
Definition: qwidget.cpp:474
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
int spacing() const
Returns the spacing between the items in the view.
Definition: qcombobox.cpp:588
void setFocus()
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its paren...
Definition: qwidget.h:432
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
static bool isEffectEnabled(Qt::UIEffect)
Returns true if effect is enabled; otherwise returns false.
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
int x() const
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
ScrollBarPolicy
Definition: qnamespace.h:1420
QAbstractItemView * view() const
Returns the list view used for the combobox popup.
Definition: qcombobox.cpp:2385
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
int currentIndex() const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QSize maximumSize() const
QHeaderView * header() const
Returns the header for the tree view.
Definition: qtreeview.cpp:302
The QModelIndex class is used to locate data in a data model.
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
The QStyleOptionComboBox class is used to describe the parameter for drawing a combobox.
Definition: qstyleoption.h:796
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
Definition: qstyleoption.h:89
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QSize minimumSize() const
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
int maximum() const
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.

◆ sizeAdjustPolicy()

SizeAdjustPolicy QComboBox::sizeAdjustPolicy ( ) const

◆ sizeHint()

QSize QComboBox::sizeHint ( ) const
virtual

This implementation caches the size hint to avoid resizing when the contents change dynamically.

Reimplemented Function

To invalidate the cached value change the sizeAdjustPolicy .

Reimplemented from QWidget.

Reimplemented in QFontComboBox.

Definition at line 2432 of file qcombobox.cpp.

Referenced by QComboBoxPrivate::_q_dataChanged(), QComboBoxPrivate::_q_rowsInserted(), QComboBoxPrivate::_q_rowsRemoved(), QComboBoxPrivate::modelChanged(), and QFontComboBox::sizeHint().

2433 {
2434  Q_D(const QComboBox);
2435  return d->recomputeSizeHint(d->sizeHint);
2436 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ validator()

const QValidator * QComboBox::validator ( ) const

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

See also
editable

Definition at line 1884 of file qcombobox.cpp.

1885 {
1886  Q_D(const QComboBox);
1887  return d->lineEdit ? d->lineEdit->validator() : 0;
1888 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ view()

QAbstractItemView * QComboBox::view ( ) const

Returns the list view used for the combobox popup.

Definition at line 2385 of file qcombobox.cpp.

Referenced by QAccessibleComboBox::actionText(), QAccessibleComboBox::childCount(), QFontComboBox::event(), hidePopup(), QAccessibleComboBox::indexOfChild(), itemDelegate(), QComboBoxPrivate::keyboardSearchString(), QAccessibleComboBox::navigate(), QFontComboBox::QFontComboBox(), setEditable(), setIconSize(), setItemDelegate(), setRootModelIndex(), QFontComboBox::setWritingSystem(), and showPopup().

2386 {
2387  Q_D(const QComboBox);
2388  return const_cast<QComboBoxPrivate*>(d)->viewContainer()->itemView();
2389 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62

◆ wheelEvent()

void QComboBox::wheelEvent ( QWheelEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 3175 of file qcombobox.cpp.

3176 {
3177  Q_D(QComboBox);
3178  if (!d->viewContainer()->isVisible()) {
3179  int newIndex = currentIndex();
3180 
3181  if (e->delta() > 0) {
3182  newIndex--;
3183  while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
3184  newIndex--;
3185  } else {
3186  newIndex++;
3187  while ((newIndex < count()) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
3188  newIndex++;
3189  }
3190 
3191  if (newIndex >= 0 && newIndex < count() && newIndex != currentIndex()) {
3192  setCurrentIndex(newIndex);
3193  d->emitActivated(d->currentIndex);
3194  }
3195  e->accept();
3196  }
3197 }
double d
Definition: qnumeric_p.h:62
void setCurrentIndex(int index)
Definition: qcombobox.cpp:2102
#define Q_D(Class)
Definition: qglobal.h:2482
int count() const
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
int delta() const
Returns the distance that the wheel is rotated, in eighths of a degree.
Definition: qevent.h:150
int currentIndex() const
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309

Properties

◆ autoCompletion

bool QComboBox::autoCompletion
private

whether the combobox provides auto-completion for editable items

Use setCompleter() instead.

Since
4.1

Use setCompleter() instead.

By default, this property is true.

See also
editable

Definition at line 80 of file qcombobox.h.

◆ autoCompletionCaseSensitivity

Qt::CaseSensitivity QComboBox::autoCompletionCaseSensitivity
private

whether string comparisons are case-sensitive or case-insensitive for auto-completion

Use setCompleter() and QCompleter::setCaseSensitivity() instead.

By default, this property is Qt::CaseInsensitive.

Use setCompleter() instead. Case sensitivity of the auto completion can be changed using QCompleter::setCaseSensitivity().

See also
autoCompletion

Definition at line 81 of file qcombobox.h.

◆ count

int QComboBox::count
private

the number of items in the combobox

By default, for an empty combo box, this property has a value of 0.

Definition at line 69 of file qcombobox.h.

Referenced by isc().

◆ currentIndex

int QComboBox::currentIndex
private

the index of the current item in the combobox.

The current index can change when inserting or removing items.

By default, for an empty combo box or a combo box in which no current item is set, this property has a value of -1.

Definition at line 71 of file qcombobox.h.

Referenced by QPrintDialogPrivate::_q_okClicked(), and QPPDOptionsEditor::setModelData().

◆ currentText

QString QComboBox::currentText
private

the current text

If the combo box is editable, the current text is the value displayed by the line edit. Otherwise, it is the value of the current item or an empty string if the combo box is empty or no current item is set.

See also
editable

Definition at line 70 of file qcombobox.h.

Referenced by QInputDialogPrivate::chooseRightTextInputWidget(), and QAccessibleComboBox::text().

◆ duplicatesEnabled

bool QComboBox::duplicatesEnabled
private

whether the user can enter duplicate items into the combobox

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

By default, this property is false (duplicates are not allowed).

Definition at line 84 of file qcombobox.h.

◆ editable

bool QComboBox::editable
private

whether the combo box can be edited by the user

Use isEditable() instead.

By default, this property is false. The effect of editing depends on the insert policy.

See also
InsertPolicy

Definition at line 68 of file qcombobox.h.

◆ frame

QComboBox::frame
private

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.

Definition at line 85 of file qcombobox.h.

◆ iconSize

QSize QComboBox::iconSize
private

the size of the icons shown in the combobox.

Unless explicitly set this returns the default value of the current style. This size is the maximum size that icons can have; icons of smaller size are not scaled up.

Definition at line 77 of file qcombobox.h.

Referenced by QMacStyle::sizeFromContents().

◆ insertPolicy

QComboBox::InsertPolicy QComboBox::insertPolicy
private

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.

See also
InsertPolicy

Definition at line 74 of file qcombobox.h.

◆ maxCount

int QComboBox::maxCount
private

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.

By default, this property's value is derived from the highest signed integer available (typically 2147483647).

Definition at line 73 of file qcombobox.h.

◆ maxVisibleItems

int QComboBox::maxVisibleItems
private

the maximum allowed size on screen of the combo box, measured in items

By default, this property has a value of 10.

Note
This property is ignored for non-editable comboboxes in styles that returns true for QStyle::SH_ComboBox_Popup such as the Mac style or the Gtk+ Style.

Definition at line 72 of file qcombobox.h.

◆ minimumContentsLength

int QComboBox::minimumContentsLength
private

the minimum number of characters that should fit into the combobox.

The default value is 0.

If this property is set to a positive value, the minimumSizeHint() and sizeHint() take it into account.

See also
sizeAdjustPolicy

Definition at line 76 of file qcombobox.h.

◆ modelColumn

int QComboBox::modelColumn
private

the column in the model that is visible.

If set prior to populating the combo box, the pop-up view will not be affected and will show the first column (using this property's default value).

By default, this property has a value of 0.

Definition at line 86 of file qcombobox.h.

◆ sizeAdjustPolicy

QComboBox::SizeAdjustPolicy QComboBox::sizeAdjustPolicy
private

the policy describing how the size of the combobox changes when the content changes

The default value is AdjustToContentsOnFirstShow .

See also
SizeAdjustPolicy

Definition at line 75 of file qcombobox.h.


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