QtBase  v6.3.1
Public Types | Public Slots | Signals | Public Member Functions | Protected Member 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:
Inheritance graph
[legend]
Collaboration diagram for QComboBox:
Collaboration graph
[legend]

Public Types

enum  InsertPolicy {
  NoInsert , InsertAtTop , InsertAtCurrent , InsertAtBottom ,
  InsertAfterCurrent , InsertBeforeCurrent , InsertAlphabetically
}
 
enum  SizeAdjustPolicy { AdjustToContents , AdjustToContentsOnFirstShow , AdjustToMinimumContentsLengthWithIcon }
 
- Public Types inherited from QWidget
enum  RenderFlag { DrawWindowBackground = 0x1 , DrawChildren = 0x2 , IgnoreMask = 0x4 }
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1 , PdmHeight , PdmWidthMM , PdmHeightMM ,
  PdmNumColors , PdmDepth , PdmDpiX , PdmDpiY ,
  PdmPhysicalDpiX , PdmPhysicalDpiY , PdmDevicePixelRatio , PdmDevicePixelRatioScaled
}
 

Public Slots

void clear ()
 
void clearEditText ()
 
void setEditText (const QString &text)
 
void setCurrentIndex (int index)
 
void setCurrentText (const QString &text)
 
- Public Slots inherited from QWidget
void setEnabled (bool)
 
void setDisabled (bool)
 
void setWindowModified (bool)
 
void setWindowTitle (const QString &)
 
void setStyleSheet (const QString &styleSheet)
 
void setFocus ()
 
void update ()
 
void repaint ()
 
virtual void setVisible (bool visible)
 
void setHidden (bool hidden)
 
void show ()
 
void hide ()
 
void showMinimized ()
 
void showMaximized ()
 
void showFullScreen ()
 
void showNormal ()
 
bool close ()
 
void raise ()
 
void lower ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Signals

void editTextChanged (const QString &)
 
void activated (int index)
 
void textActivated (const QString &)
 
void highlighted (int index)
 
void textHighlighted (const QString &)
 
void currentIndexChanged (int index)
 
void currentTextChanged (const QString &)
 
- Signals inherited from QWidget
void windowTitleChanged (const QString &title)
 
void windowIconChanged (const QIcon &icon)
 
void windowIconTextChanged (const QString &iconText)
 
void customContextMenuRequested (const QPoint &pos)
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 

Public Member Functions

 QComboBox (QWidget *parent=nullptr)
 
 ~QComboBox ()
 
int maxVisibleItems () const
 
void setMaxVisibleItems (int maxItems)
 
int count () const
 
void setMaxCount (int max)
 
int maxCount () const
 
bool duplicatesEnabled () const
 
void setDuplicatesEnabled (bool enable)
 
void setFrame (bool)
 
bool hasFrame () const
 
int findText (const QString &text, Qt::MatchFlags flags=static_cast< Qt::MatchFlags >(Qt::MatchExactly|Qt::MatchCaseSensitive)) const
 
int findData (const QVariant &data, int role=Qt::UserRole, Qt::MatchFlags flags=static_cast< Qt::MatchFlags >(Qt::MatchExactly|Qt::MatchCaseSensitive)) const
 
InsertPolicy insertPolicy () const
 
void setInsertPolicy (InsertPolicy policy)
 
SizeAdjustPolicy sizeAdjustPolicy () const
 
void setSizeAdjustPolicy (SizeAdjustPolicy policy)
 
int minimumContentsLength () const
 
void setMinimumContentsLength (int characters)
 
QSize iconSize () const
 
void setIconSize (const QSize &size)
 
void setPlaceholderText (const QString &placeholderText)
 
QString placeholderText () const
 
bool isEditable () const
 
void setEditable (bool editable)
 
void setLineEdit (QLineEdit *edit)
 
QLineEditlineEdit () const
 
void setValidator (const QValidator *v)
 
const QValidatorvalidator () const
 
QAbstractItemDelegateitemDelegate () const
 
void setItemDelegate (QAbstractItemDelegate *delegate)
 
QAbstractItemModelmodel () const
 
virtual void setModel (QAbstractItemModel *model)
 
QModelIndex rootModelIndex () const
 
void setRootModelIndex (const QModelIndex &index)
 
int modelColumn () const
 
void setModelColumn (int visibleColumn)
 
int currentIndex () const
 
QString currentText () const
 
QVariant currentData (int role=Qt::UserRole) const
 
QString itemText (int index) const
 
QIcon itemIcon (int index) const
 
QVariant itemData (int index, int role=Qt::UserRole) const
 
void addItem (const QString &text, const QVariant &userData=QVariant())
 
void addItem (const QIcon &icon, const QString &text, const QVariant &userData=QVariant())
 
void addItems (const QStringList &texts)
 
void insertItem (int index, const QString &text, const QVariant &userData=QVariant())
 
void insertItem (int index, const QIcon &icon, const QString &text, const QVariant &userData=QVariant())
 
void insertItems (int index, const QStringList &texts)
 
void insertSeparator (int index)
 
void removeItem (int index)
 
void setItemText (int index, const QString &text)
 
void setItemIcon (int index, const QIcon &icon)
 
void setItemData (int index, const QVariant &value, int role=Qt::UserRole)
 
QAbstractItemViewview () const
 
void setView (QAbstractItemView *itemView)
 
QSize sizeHint () const override
 
QSize minimumSizeHint () const override
 
virtual void showPopup ()
 
virtual void hidePopup ()
 
bool event (QEvent *event) override
 
QVariant inputMethodQuery (Qt::InputMethodQuery) const override
 
Q_INVOKABLE QVariant inputMethodQuery (Qt::InputMethodQuery query, const QVariant &argument) const
 
- Public Member Functions inherited from QWidget
 QWidget (QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 
 ~QWidget ()
 
int devType () const override
 
WId winId () const
 
void createWinId ()
 
WId internalWinId () const
 
WId effectiveWinId () const
 
QStylestyle () const
 
void setStyle (QStyle *)
 
bool isWindow () const
 
bool isModal () const
 
Qt::WindowModality windowModality () const
 
void setWindowModality (Qt::WindowModality windowModality)
 
bool isEnabled () const
 
bool isEnabledTo (const QWidget *) const
 
QRect frameGeometry () const
 
const QRectgeometry () const
 
QRect normalGeometry () const
 
int x () const
 
int y () const
 
QPoint pos () const
 
QSize frameSize () const
 
QSize size () const
 
int width () const
 
int height () const
 
QRect rect () const
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
QSize minimumSize () const
 
QSize maximumSize () const
 
int minimumWidth () const
 
int minimumHeight () const
 
int maximumWidth () const
 
int maximumHeight () const
 
void setMinimumSize (const QSize &)
 
void setMinimumSize (int minw, int minh)
 
void setMaximumSize (const QSize &)
 
void setMaximumSize (int maxw, int maxh)
 
void setMinimumWidth (int minw)
 
void setMinimumHeight (int minh)
 
void setMaximumWidth (int maxw)
 
void setMaximumHeight (int maxh)
 
QSize sizeIncrement () const
 
void setSizeIncrement (const QSize &)
 
void setSizeIncrement (int w, int h)
 
QSize baseSize () const
 
void setBaseSize (const QSize &)
 
void setBaseSize (int basew, int baseh)
 
void setFixedSize (const QSize &)
 
void setFixedSize (int w, int h)
 
void setFixedWidth (int w)
 
void setFixedHeight (int h)
 
QPointF mapToGlobal (const QPointF &) const
 
QPoint mapToGlobal (const QPoint &) const
 
QPointF mapFromGlobal (const QPointF &) const
 
QPoint mapFromGlobal (const QPoint &) const
 
QPointF mapToParent (const QPointF &) const
 
QPoint mapToParent (const QPoint &) const
 
QPointF mapFromParent (const QPointF &) const
 
QPoint mapFromParent (const QPoint &) const
 
QPointF mapTo (const QWidget *, const QPointF &) const
 
QPoint mapTo (const QWidget *, const QPoint &) const
 
QPointF mapFrom (const QWidget *, const QPointF &) const
 
QPoint mapFrom (const QWidget *, const QPoint &) const
 
QWidgetwindow () const
 
QWidgetnativeParentWidget () const
 
QWidgettopLevelWidget () const
 
const QPalettepalette () const
 
void setPalette (const QPalette &)
 
void setBackgroundRole (QPalette::ColorRole)
 
QPalette::ColorRole backgroundRole () const
 
void setForegroundRole (QPalette::ColorRole)
 
QPalette::ColorRole foregroundRole () const
 
const QFontfont () const
 
void setFont (const QFont &)
 
QFontMetrics fontMetrics () const
 
QFontInfo fontInfo () const
 
QCursor cursor () const
 
void setCursor (const QCursor &)
 
void unsetCursor ()
 
void setMouseTracking (bool enable)
 
bool hasMouseTracking () const
 
bool underMouse () const
 
void setTabletTracking (bool enable)
 
bool hasTabletTracking () const
 
void setMask (const QBitmap &)
 
void setMask (const QRegion &)
 
QRegion mask () const
 
void clearMask ()
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 
Q_INVOKABLE QPixmap grab (const QRect &rectangle=QRect(QPoint(0, 0), QSize(-1, -1)))
 
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 
void ungrabGesture (Qt::GestureType type)
 
QString styleSheet () const
 
QString windowTitle () const
 
void setWindowIcon (const QIcon &icon)
 
QIcon windowIcon () const
 
void setWindowIconText (const QString &)
 
QString windowIconText () const
 
void setWindowRole (const QString &)
 
QString windowRole () const
 
void setWindowFilePath (const QString &filePath)
 
QString windowFilePath () const
 
void setWindowOpacity (qreal level)
 
qreal windowOpacity () const
 
bool isWindowModified () const
 
QString accessibleName () const
 
void setAccessibleName (const QString &name)
 
QString accessibleDescription () const
 
void setAccessibleDescription (const QString &description)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
Qt::LayoutDirection layoutDirection () const
 
void unsetLayoutDirection ()
 
void setLocale (const QLocale &locale)
 
QLocale locale () const
 
void unsetLocale ()
 
bool isRightToLeft () const
 
bool isLeftToRight () const
 
bool isActiveWindow () const
 
void activateWindow ()
 
void clearFocus ()
 
void setFocus (Qt::FocusReason reason)
 
Qt::FocusPolicy focusPolicy () const
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
bool hasFocus () const
 
void setFocusProxy (QWidget *)
 
QWidgetfocusProxy () const
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void grabMouse ()
 
void grabMouse (const QCursor &)
 
void releaseMouse ()
 
void grabKeyboard ()
 
void releaseKeyboard ()
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 
void releaseShortcut (int id)
 
void setShortcutEnabled (int id, bool enable=true)
 
void setShortcutAutoRepeat (int id, bool enable=true)
 
bool updatesEnabled () const
 
void setUpdatesEnabled (bool enable)
 
void update (int x, int y, int w, int h)
 
void update (const QRect &)
 
void update (const QRegion &)
 
void repaint (int x, int y, int w, int h)
 
void repaint (const QRect &)
 
void repaint (const QRegion &)
 
void stackUnder (QWidget *)
 
void move (int x, int y)
 
void move (const QPoint &)
 
void resize (int w, int h)
 
void resize (const QSize &)
 
void setGeometry (int x, int y, int w, int h)
 
void setGeometry (const QRect &)
 
QByteArray saveGeometry () const
 
bool restoreGeometry (const QByteArray &geometry)
 
void adjustSize ()
 
bool isVisible () const
 
bool isVisibleTo (const QWidget *) const
 
bool isHidden () const
 
bool isMinimized () const
 
bool isMaximized () const
 
bool isFullScreen () const
 
Qt::WindowStates windowState () const
 
void setWindowState (Qt::WindowStates state)
 
void overrideWindowState (Qt::WindowStates state)
 
QSizePolicy sizePolicy () const
 
void setSizePolicy (QSizePolicy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 
virtual int heightForWidth (int) const
 
virtual bool hasHeightForWidth () const
 
QRegion visibleRegion () const
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setContentsMargins (const QMargins &margins)
 The setContentsMargins function sets the margins around the widget's contents. More...
 
QMargins contentsMargins () const
 The contentsMargins function returns the widget's contents margins. More...
 
QRect contentsRect () const
 
QLayoutlayout () const
 
void setLayout (QLayout *)
 
void updateGeometry ()
 
void setParent (QWidget *parent)
 
void setParent (QWidget *parent, Qt::WindowFlags f)
 
void scroll (int dx, int dy)
 
void scroll (int dx, int dy, const QRect &)
 
QWidgetfocusWidget () const
 
QWidgetnextInFocusChain () const
 
QWidgetpreviousInFocusChain () const
 The previousInFocusChain function returns the previous widget in this widget's focus chain. More...
 
bool acceptDrops () const
 
void setAcceptDrops (bool on)
 
void addAction (QAction *action)
 
void addActions (const QList< QAction * > &actions)
 
void insertActions (QAction *before, const QList< QAction * > &actions)
 
void insertAction (QAction *before, QAction *action)
 
void removeAction (QAction *action)
 
QList< QAction * > actions () const
 
QActionaddAction (const QString &text)
 
QActionaddAction (const QIcon &icon, const QString &text)
 
QActionaddAction (const QString &text, const QObject *receiver, const char *member, Qt::ConnectionType type=Qt::AutoConnection)
 
QActionaddAction (const QIcon &icon, const QString &text, const QObject *receiver, const char *member, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename... Args, typename = compatible_action_slot_args<Args...>>
QActionaddAction (const QString &text, Args &&...args)
 
template<typename... Args, typename = compatible_action_slot_args<Args...>>
QActionaddAction (const QIcon &icon, const QString &text, Args &&...args)
 
QWidgetparentWidget () const
 
void setWindowFlags (Qt::WindowFlags type)
 
Qt::WindowFlags windowFlags () const
 
void setWindowFlag (Qt::WindowType, bool on=true)
 
void overrideWindowFlags (Qt::WindowFlags type)
 
Qt::WindowType windowType () const
 
QWidgetchildAt (int x, int y) const
 
QWidgetchildAt (const QPoint &p) const
 
void setAttribute (Qt::WidgetAttribute, bool on=true)
 
bool testAttribute (Qt::WidgetAttribute) const
 
QPaintEnginepaintEngine () const override
 
void ensurePolished () const
 
bool isAncestorOf (const QWidget *child) const
 
bool autoFillBackground () const
 
void setAutoFillBackground (bool enabled)
 
QBackingStorebackingStore () const
 
QWindowwindowHandle () const
 
QScreenscreen () const
 
void setScreen (QScreen *)
 
Qt::InputMethodHints inputMethodHints () const
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 
virtual ~QObject ()
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const noexcept
 
bool blockSignals (bool b) noexcept
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 
template<typename T >
T findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
const QObjectListchildren () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 
void dumpObjectInfo () const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 
- Public Member Functions inherited from QPaintDevice
virtual ~QPaintDevice ()
 
bool paintingActive () const
 
int width () const
 
int height () const
 
int widthMM () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
qreal devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int colorCount () const
 
int depth () const
 

Protected Member Functions

void focusInEvent (QFocusEvent *e) override
 
void focusOutEvent (QFocusEvent *e) override
 
void changeEvent (QEvent *e) override
 
void resizeEvent (QResizeEvent *e) override
 
void paintEvent (QPaintEvent *e) override
 
void showEvent (QShowEvent *e) override
 
void hideEvent (QHideEvent *e) override
 
void mousePressEvent (QMouseEvent *e) override
 
void mouseReleaseEvent (QMouseEvent *e) override
 
void keyPressEvent (QKeyEvent *e) override
 
void keyReleaseEvent (QKeyEvent *e) override
 
void contextMenuEvent (QContextMenuEvent *e) override
 
void inputMethodEvent (QInputMethodEvent *) override
 
virtual void initStyleOption (QStyleOptionComboBox *option) const
 
 QComboBox (QComboBoxPrivate &, QWidget *)
 
- Protected Member Functions inherited from QWidget
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 
virtual void mouseMoveEvent (QMouseEvent *event)
 
virtual void enterEvent (QEnterEvent *event)
 
virtual void leaveEvent (QEvent *event)
 
virtual void moveEvent (QMoveEvent *event)
 
virtual void closeEvent (QCloseEvent *event)
 
virtual void actionEvent (QActionEvent *event)
 
virtual bool nativeEvent (const QByteArray &eventType, void *message, qintptr *result)
 
int metric (PaintDeviceMetric) const override
 
void initPainter (QPainter *painter) const override
 
QPaintDeviceredirected (QPoint *offset) const override
 
QPaintersharedPainter () const override
 
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 
virtual bool focusNextPrevChild (bool next)
 
bool focusNextChild ()
 
bool focusPreviousChild ()
 
 QWidget (QWidgetPrivate &d, QWidget *parent, Qt::WindowFlags f)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Member Functions inherited from QPaintDevice
 QPaintDevice () noexcept
 

Properties

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

Additional Inherited Members

- Static Public Member Functions inherited from QWidget
static void setTabOrder (QWidget *, QWidget *)
 
static QWidgetmouseGrabber ()
 
static QWidgetkeyboardGrabber ()
 
static QWidgetfind (WId)
 
static QWidgetcreateWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Static Public Member Functions inherited from QPaintDevice
static qreal devicePixelRatioFScale ()
 
- Protected Slots inherited from QWidget
void updateMicroFocus (Qt::InputMethodQuery query=Qt::ImQueryAll)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Attributes inherited from QPaintDevice
ushort painters
 

Detailed Description

The QComboBox widget is a combined button and popup list.

\inmodule QtWidgets

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 three signals emitted if the current item of a combobox changes, currentIndexChanged(), currentTextChanged() and activated(). currentIndexChanged() and currentTextChanged() are 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 \l InsertAtBottom 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 \l{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 \l{QAbstractItemView::}{SelectionMode} of the view(), e.g., by using \l{QAbstractItemView::}{setSelectionMode()}.

See also
QLineEdit, QSpinBox, QRadioButton, QButtonGroup

Definition at line 59 of file qcombobox.h.

Member Enumeration Documentation

◆ InsertPolicy

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

\value NoInsert The string will not be inserted into the combobox. \value InsertAtTop The string will be inserted as the first item in the combobox. \value InsertAtCurrent The current item will be replaced by the string. \value InsertAtBottom The string will be inserted after the last item in the combobox. \value InsertAfterCurrent The string is inserted after the current item in the combobox. \value InsertBeforeCurrent The string is inserted before the current item in the combobox. \value InsertAlphabetically The string is inserted in the alphabetic order in the combobox.

Enumerator
NoInsert 
InsertAtTop 
InsertAtCurrent 
InsertAtBottom 
InsertAfterCurrent 
InsertBeforeCurrent 
InsertAlphabetically 

Definition at line 103 of file qcombobox.h.

◆ SizeAdjustPolicy

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

\value AdjustToContents The combobox will always adjust to the contents \value AdjustToContentsOnFirstShow The combobox will adjust to its contents the first time it is shown. \value AdjustToMinimumContentsLengthWithIcon The combobox will adjust to \l minimumContentsLength plus space for an icon. For performance reasons use this policy on large models.

Enumerator
AdjustToContents 
AdjustToContentsOnFirstShow 
AdjustToMinimumContentsLengthWithIcon 

Definition at line 117 of file qcombobox.h.

Constructor & Destructor Documentation

◆ QComboBox() [1/2]

QComboBox::QComboBox ( QWidget parent = nullptr)
explicit

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

Definition at line 958 of file qcombobox.cpp.

◆ ~QComboBox()

QComboBox::~QComboBox ( )

Destroys the combobox.

Definition at line 1442 of file qcombobox.cpp.

Here is the call graph for this function:

◆ QComboBox() [2/2]

QComboBox::QComboBox ( QComboBoxPrivate dd,
QWidget parent 
)
protected

Definition at line 968 of file qcombobox.cpp.

Member Function Documentation

◆ activated

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

Here is the caller graph for this function:

◆ addItem() [1/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 262 of file qcombobox.h.

Here is the call graph for this function:

◆ addItem() [2/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 260 of file qcombobox.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 171 of file qcombobox.h.

Here is the caller graph for this function:

◆ changeEvent()

void QComboBox::changeEvent ( QEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 2967 of file qcombobox.cpp.

Here is the call graph for this function:

◆ 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 2901 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearEditText

void QComboBox::clearEditText ( )
slot

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

Definition at line 2914 of file qcombobox.cpp.

Here is the call graph for this function:

◆ contextMenuEvent()

void QComboBox::contextMenuEvent ( QContextMenuEvent e)
overrideprotectedvirtual

\reimp

\reimp

Reimplemented from QWidget.

Definition at line 3370 of file qcombobox.cpp.

◆ count()

int QComboBox::count ( ) const

Definition at line 1487 of file qcombobox.cpp.

◆ currentData()

QVariant QComboBox::currentData ( int  role = Qt::UserRole) const

Definition at line 2211 of file qcombobox.cpp.

◆ currentIndex()

int QComboBox::currentIndex ( ) const

Definition at line 2127 of file qcombobox.cpp.

◆ currentIndexChanged

void QComboBox::currentIndexChanged ( int  index)
signal
Since
4.1

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

Here is the caller graph for this function:

◆ currentText()

QString QComboBox::currentText ( ) const

Definition at line 2193 of file qcombobox.cpp.

◆ currentTextChanged

void QComboBox::currentTextChanged ( const QString text)
signal
Since
5.0

This signal is sent whenever currentText changes. The new value is passed as text.

Here is the caller graph for this function:

◆ duplicatesEnabled()

bool QComboBox::duplicatesEnabled ( ) const

Definition at line 1535 of file qcombobox.cpp.

◆ 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.

Here is the caller graph for this function:

◆ event()

bool QComboBox::event ( QEvent event)
overridevirtual

\reimp

Reimplemented from QWidget.

Reimplemented in QFontComboBox.

Definition at line 3077 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 1561 of file qcombobox.cpp.

Here is the caller graph for this function:

◆ 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 97 of file qcombobox.h.

Here is the caller graph for this function:

◆ focusInEvent()

void QComboBox::focusInEvent ( QFocusEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 2942 of file qcombobox.cpp.

Here is the call graph for this function:

◆ focusOutEvent()

void QComboBox::focusOutEvent ( QFocusEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 2958 of file qcombobox.cpp.

Here is the call graph for this function:

◆ hasFrame()

bool QComboBox::hasFrame ( ) const

Definition at line 3482 of file qcombobox.cpp.

◆ hideEvent()

void QComboBox::hideEvent ( QHideEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 3069 of file qcombobox.cpp.

Here is the call graph for this function:

◆ 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 2836 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ highlighted

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.

◆ iconSize()

QSize QComboBox::iconSize ( ) const

Definition at line 1664 of file qcombobox.cpp.

Here is the call graph for this function:

◆ initStyleOption()

void QComboBox::initStyleOption ( QStyleOptionComboBox option) const
protectedvirtual

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 1226 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ inputMethodEvent()

void QComboBox::inputMethodEvent ( QInputMethodEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 3409 of file qcombobox.cpp.

◆ inputMethodQuery() [1/2]

QVariant QComboBox::inputMethodQuery ( Qt::InputMethodQuery  query,
const QVariant argument 
) const

Definition at line 3435 of file qcombobox.cpp.

Here is the call graph for this function:

◆ inputMethodQuery() [2/2]

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

\reimp

Reimplemented from QWidget.

Definition at line 3425 of file qcombobox.cpp.

Here is the call graph for this function:

◆ insertItem() [1/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 2274 of file qcombobox.cpp.

Here is the call graph for this function:

◆ insertItem() [2/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 266 of file qcombobox.h.

Here is the caller graph for this function:

◆ 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 2325 of file qcombobox.cpp.

Here is the call graph for this function:

◆ insertPolicy()

QComboBox::InsertPolicy QComboBox::insertPolicy ( ) const

Definition at line 1582 of file qcombobox.cpp.

◆ insertSeparator()

void QComboBox::insertSeparator ( int  index)
Since
4.4

Inserts a separator item 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
insertItem()

Definition at line 2374 of file qcombobox.cpp.

Here is the call graph for this function:

◆ isEditable()

bool QComboBox::isEditable ( ) const

Definition at line 1737 of file qcombobox.cpp.

Here is the caller graph for this function:

◆ 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 an invalid QVariant if there is no data for this role.

Definition at line 2241 of file qcombobox.cpp.

Here is the caller graph for this function:

◆ itemDelegate()

QAbstractItemDelegate * QComboBox::itemDelegate ( ) const

Returns the item delegate used by the popup list view.

See also
setItemDelegate()

Definition at line 1970 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ itemIcon()

QIcon QComboBox::itemIcon ( int  index) const

Returns the icon for the given index in the combobox.

Definition at line 2230 of file qcombobox.cpp.

◆ itemText()

QString QComboBox::itemText ( int  index) const

Returns the text for the given index in the combobox.

Definition at line 2220 of file qcombobox.cpp.

Here is the caller graph for this function:

◆ keyPressEvent()

void QComboBox::keyPressEvent ( QKeyEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 3180 of file qcombobox.cpp.

Here is the call graph for this function:

◆ keyReleaseEvent()

void QComboBox::keyReleaseEvent ( QKeyEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 3323 of file qcombobox.cpp.

Here is the call graph for this function:

◆ lineEdit()

QLineEdit * QComboBox::lineEdit ( ) const

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

Only editable combo boxes have a line edit.

Definition at line 1884 of file qcombobox.cpp.

Here is the caller graph for this function:

◆ maxCount()

int QComboBox::maxCount ( ) const

Definition at line 1520 of file qcombobox.cpp.

◆ maxVisibleItems()

int QComboBox::maxVisibleItems ( ) const

Definition at line 1464 of file qcombobox.cpp.

◆ minimumContentsLength()

int QComboBox::minimumContentsLength ( ) const

Definition at line 1633 of file qcombobox.cpp.

◆ minimumSizeHint()

QSize QComboBox::minimumSizeHint ( ) const
overridevirtual

\reimp

Reimplemented from QWidget.

Definition at line 2470 of file qcombobox.cpp.

◆ model()

QAbstractItemModel * QComboBox::model ( ) const

Returns the model used by the combobox.

Definition at line 2003 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ modelColumn()

int QComboBox::modelColumn ( ) const

Definition at line 3510 of file qcombobox.cpp.

◆ mousePressEvent()

void QComboBox::mousePressEvent ( QMouseEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 3117 of file qcombobox.cpp.

Here is the call graph for this function:

◆ mouseReleaseEvent()

void QComboBox::mouseReleaseEvent ( QMouseEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 3169 of file qcombobox.cpp.

Here is the call graph for this function:

◆ paintEvent()

void QComboBox::paintEvent ( QPaintEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 3033 of file qcombobox.cpp.

Here is the call graph for this function:

◆ placeholderText()

QString QComboBox::placeholderText ( ) const

Definition at line 1719 of file qcombobox.cpp.

◆ 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 2391 of file qcombobox.cpp.

◆ resizeEvent()

void QComboBox::resizeEvent ( QResizeEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 3024 of file qcombobox.cpp.

◆ rootModelIndex()

QModelIndex QComboBox::rootModelIndex ( ) const

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

See also
setRootModelIndex()

Definition at line 2097 of file qcombobox.cpp.

Here is the caller graph for this function:

◆ setCurrentIndex

void QComboBox::setCurrentIndex ( int  index)
slot

Definition at line 2133 of file qcombobox.cpp.

Here is the caller graph for this function:

◆ setCurrentText

void QComboBox::setCurrentText ( const QString text)
slot

Definition at line 2140 of file qcombobox.cpp.

Here is the call graph for this function:

◆ setDuplicatesEnabled()

void QComboBox::setDuplicatesEnabled ( bool  enable)

Definition at line 1541 of file qcombobox.cpp.

Here is the caller graph for this function:

◆ setEditable()

void QComboBox::setEditable ( bool  editable)

Definition at line 1773 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setEditText

void QComboBox::setEditText ( const QString text)
slot

Sets the text in the combobox's text edit.

Definition at line 2928 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFrame()

void QComboBox::setFrame ( bool  enable)

Definition at line 3489 of file qcombobox.cpp.

Here is the call graph for this function:

◆ setIconSize()

void QComboBox::setIconSize ( const QSize size)

Definition at line 1674 of file qcombobox.cpp.

Here is the call graph for this function:

◆ setInsertPolicy()

void QComboBox::setInsertPolicy ( InsertPolicy  policy)

Definition at line 1588 of file qcombobox.cpp.

Here is the caller graph for this function:

◆ 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 2427 of file qcombobox.cpp.

◆ setItemDelegate()

void QComboBox::setItemDelegate ( QAbstractItemDelegate delegate)

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

Any existing delegate will be removed, but not deleted. QComboBox does not take ownership of 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 \l{QAbstractItemDelegate::}{closeEditor()} signal, and attempt to access, modify or close an editor that has already been closed.
See also
itemDelegate()

Definition at line 1990 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 2414 of file qcombobox.cpp.

◆ 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 2402 of file qcombobox.cpp.

Here is the caller graph for this function:

◆ 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.

Note
Since the combobox's line edit owns the QCompleter, any previous call to setCompleter() will no longer have any effect.

Definition at line 1816 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMaxCount()

void QComboBox::setMaxCount ( int  max)

Definition at line 1505 of file qcombobox.cpp.

◆ setMaxVisibleItems()

void QComboBox::setMaxVisibleItems ( int  maxItems)

Definition at line 1470 of file qcombobox.cpp.

◆ setMinimumContentsLength()

void QComboBox::setMinimumContentsLength ( int  characters)

Definition at line 1639 of file qcombobox.cpp.

Here is the call graph for this function:

◆ setModel()

void QComboBox::setModel ( QAbstractItemModel model)
virtual

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

Note
If the combobox is editable, then the model will also be set on the completer of the line edit.
See also
clear() setCompleter()

Definition at line 2022 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setModelColumn()

void QComboBox::setModelColumn ( int  visibleColumn)

Definition at line 3516 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPlaceholderText()

void QComboBox::setPlaceholderText ( const QString placeholderText)

Definition at line 1702 of file qcombobox.cpp.

Here is the call graph for this function:

◆ 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 2108 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSizeAdjustPolicy()

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

Definition at line 1610 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setValidator()

void QComboBox::setValidator ( const QValidator validator)

Sets the validator to use instead of the current validator.

Note
The validator is removed when the \l editable property becomes false.

Definition at line 1899 of file qcombobox.cpp.

◆ 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 2454 of file qcombobox.cpp.

Here is the call graph for this function:

◆ showEvent()

void QComboBox::showEvent ( QShowEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 3055 of file qcombobox.cpp.

Here is the call graph for this function:

◆ showPopup()

void QComboBox::showPopup ( )
virtual

Displays the list of items in the combobox. If the list is empty then 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 2580 of file qcombobox.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sizeAdjustPolicy()

QComboBox::SizeAdjustPolicy QComboBox::sizeAdjustPolicy ( ) const

Definition at line 1604 of file qcombobox.cpp.

◆ sizeHint()

QSize QComboBox::sizeHint ( ) const
overridevirtual

\reimp

This implementation caches the size hint to avoid resizing when the contents change dynamically. To invalidate the cached value change the \l sizeAdjustPolicy.

Reimplemented from QWidget.

Reimplemented in QFontComboBox.

Definition at line 2483 of file qcombobox.cpp.

Here is the caller graph for this function:

◆ textActivated

void QComboBox::textActivated ( const QString text)
signal
Since
5.14

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

Here is the caller graph for this function:

◆ textHighlighted

void QComboBox::textHighlighted ( const QString text)
signal
Since
5.14

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

◆ 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 1912 of file qcombobox.cpp.

◆ view()

QAbstractItemView * QComboBox::view ( ) const

Returns the list view used for the combobox popup.

Definition at line 2439 of file qcombobox.cpp.

Here is the caller graph for this function:

Property Documentation

◆ count

QComboBox::count
read

the number of items in the combobox

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

Definition at line 270 of file qcombobox.h.

◆ currentData

QComboBox::currentData
read

the data for the current item

Since
5.2

By default, for an empty combo box or a combo box in which no current item is set, this property contains an invalid QVariant.

Definition at line 270 of file qcombobox.h.

◆ currentIndex

QComboBox::currentIndex
readwrite

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 270 of file qcombobox.h.

◆ currentText

QComboBox::currentText
readwrite

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.

The setter setCurrentText() simply calls setEditText() if the combo box is editable. Otherwise, if there is a matching text in the list, currentIndex is set to the corresponding index.

See also
editable, setEditText()

Definition at line 270 of file qcombobox.h.

◆ duplicatesEnabled

QComboBox::duplicatesEnabled
readwrite

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 270 of file qcombobox.h.

◆ editable

QComboBox::editable
readwrite

whether the combo box can be edited by the user

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

Note
When disabling the editable state, the validator and completer are removed.
See also
InsertPolicy

Definition at line 270 of file qcombobox.h.

◆ frame

QComboBox::frame
readwrite

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 270 of file qcombobox.h.

◆ iconSize

QComboBox::iconSize
readwrite

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 270 of file qcombobox.h.

◆ insertPolicy

QComboBox::insertPolicy
readwrite

the policy used to determine where user-inserted items should appear in the combobox

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

See also
InsertPolicy

Definition at line 270 of file qcombobox.h.

◆ maxCount

QComboBox::maxCount
readwrite

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 270 of file qcombobox.h.

◆ maxVisibleItems

QComboBox::maxVisibleItems
readwrite

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 270 of file qcombobox.h.

◆ minimumContentsLength

QComboBox::minimumContentsLength
readwrite

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 270 of file qcombobox.h.

◆ modelColumn

QComboBox::modelColumn
readwrite

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.

Note
In an editable combobox, the visible column will also become the \l{QCompleter::completionColumn}{completion column}.

Definition at line 270 of file qcombobox.h.

◆ placeholderText

QComboBox::placeholderText
readwrite

Sets a placeholderText text shown when no valid index is set.

The placeholderText will be shown when an invalid index is set. The text is not accessible in the dropdown list. When this function is called before items are added the placeholder text will be shown, otherwise you have to call setCurrentIndex(-1) programmatically if you want to show the placeholder text. Set an empty placeholder text to reset the setting.

When the QComboBox is editable, use QLineEdit::setPlaceholderText() instead.

Since
5.15

Definition at line 270 of file qcombobox.h.

◆ sizeAdjustPolicy

QComboBox::sizeAdjustPolicy
readwrite

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

The default value is \l AdjustToContentsOnFirstShow.

See also
SizeAdjustPolicy

Definition at line 270 of file qcombobox.h.


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