CopperSpice API
1.9.2
|
The QComboBox widget is a combined button and popup list. More...
Public Types | |
enum | InsertPolicy |
enum | SizeAdjustPolicy |
Public Types inherited from QWidget | |
enum | RenderFlag |
Public Types inherited from QPaintDevice | |
enum | PaintDeviceMetric |
Public Signals | |
void | activated (const QString &text) |
void | activated (int index) |
void | currentIndexChanged (const QString &text) |
void | currentIndexChanged (int index) |
void | currentTextChanged (const QString &str) |
void | editTextChanged (const QString &text) |
void | highlighted (const QString &text) |
void | highlighted (int index) |
Public Signals inherited from QWidget | |
void | customContextMenuRequested (const QPoint &pos) |
void | windowIconChanged (const QIcon &icon) |
void | windowIconTextChanged (const QString &iconText) |
void | windowTitleChanged (const QString &title) |
Public Signals inherited from QObject | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
Public Slots | |
void | clear () |
void | clearEditText () |
void | setCurrentIndex (int index) |
void | setCurrentText (const QString &text) |
void | setEditText (const QString &text) |
Public Slots inherited from QWidget | |
bool | close () |
void | hide () |
void | lower () |
void | raise () |
void | repaint () |
void | setDisabled (bool disable) |
void | setEnabled (bool enable) |
void | setFocus () |
void | setHidden (bool hidden) |
void | setStyleSheet (const QString &styleSheet) |
virtual void | setVisible (bool visible) |
void | setWindowModified (bool modified) |
void | setWindowTitle (const QString &title) |
void | show () |
void | showFullScreen () |
void | showMaximized () |
void | showMinimized () |
void | showNormal () |
void | update () |
Public Slots inherited from QObject | |
void | deleteLater () |
Public Methods | |
QComboBox (QWidget *parent=nullptr) | |
~QComboBox () | |
void | addItem (const QIcon &icon, const QString &text, const QVariant &userData=QVariant ()) |
void | addItem (const QString &text, const QVariant &userData=QVariant ()) |
void | addItems (const QStringList &texts) |
bool | autoCompletion () const |
Qt::CaseSensitivity | autoCompletionCaseSensitivity () const |
QCompleter * | completer () const |
int | count () const |
QVariant | currentData (int role=Qt::UserRole) const |
int | currentIndex () const |
QString | currentText () const |
bool | duplicatesEnabled () const |
bool | event (QEvent *event) override |
int | findData (const QVariant &data, int role=Qt::UserRole, Qt::MatchFlags flags=static_cast< Qt::MatchFlags >(Qt::MatchExactly|Qt::MatchCaseSensitive)) const |
int | findText (const QString &text, Qt::MatchFlags flags=static_cast< Qt::MatchFlags >(Qt::MatchExactly|Qt::MatchCaseSensitive)) const |
bool | hasFrame () const |
virtual void | hidePopup () |
QSize | iconSize () const |
QVariant | inputMethodQuery (Qt::InputMethodQuery query) const override |
void | insertItem (int index, const QIcon &icon, const QString &text, const QVariant &userData=QVariant ()) |
void | insertItem (int index, const QString &text, const QVariant &userData=QVariant ()) |
void | insertItems (int index, const QStringList &list) |
InsertPolicy | insertPolicy () const |
void | insertSeparator (int index) |
bool | isEditable () const |
QVariant | itemData (int index, int role=Qt::UserRole) const |
QAbstractItemDelegate * | itemDelegate () const |
QIcon | itemIcon (int index) const |
QString | itemText (int index) const |
QLineEdit * | lineEdit () const |
int | maxCount () const |
int | maxVisibleItems () const |
int | minimumContentsLength () const |
QSize | minimumSizeHint () const override |
QAbstractItemModel * | model () const |
int | modelColumn () const |
void | removeItem (int index) |
QModelIndex | rootModelIndex () const |
void | setAutoCompletion (bool enable) |
void | setAutoCompletionCaseSensitivity (Qt::CaseSensitivity sensitivity) |
void | setCompleter (QCompleter *completer) |
void | setDuplicatesEnabled (bool enable) |
void | setEditable (bool editable) |
void | setFrame (bool enable) |
void | setIconSize (const QSize &size) |
void | setInsertPolicy (InsertPolicy policy) |
void | setItemData (int index, const QVariant &value, int role=Qt::UserRole) |
void | setItemDelegate (QAbstractItemDelegate *delegate) |
void | setItemIcon (int index, const QIcon &icon) |
void | setItemText (int index, const QString &text) |
void | setLineEdit (QLineEdit *edit) |
void | setMaxCount (int max) |
void | setMaxVisibleItems (int maxItems) |
void | setMinimumContentsLength (int characters) |
void | setModel (QAbstractItemModel *model) |
void | setModelColumn (int visibleColumn) |
void | setRootModelIndex (const QModelIndex &index) |
void | setSizeAdjustPolicy (SizeAdjustPolicy policy) |
void | setValidator (const QValidator *validator) |
void | setView (QAbstractItemView *itemView) |
virtual void | showPopup () |
SizeAdjustPolicy | sizeAdjustPolicy () const |
QSize | sizeHint () const override |
const QValidator * | validator () const |
QAbstractItemView * | view () const |
Public Methods inherited from QWidget | |
QWidget (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag) | |
~QWidget () | |
bool | acceptDrops () const |
QString | accessibleDescription () const |
QString | accessibleName () const |
QList< QAction * > | actions () const |
void | activateWindow () |
void | addAction (QAction *action) |
void | addActions (const QList< QAction * > &actions) |
void | adjustSize () |
bool | autoFillBackground () const |
QPalette::ColorRole | backgroundRole () const |
QBackingStore * | backingStore () const |
QSize | baseSize () const |
QWidget * | childAt (const QPoint &position) const |
QWidget * | childAt (int x, int y) const |
QRect | childrenRect () const |
QRegion | childrenRegion () const |
void | clearFocus () |
void | clearMask () |
QMargins | contentsMargins () const |
QRect | contentsRect () const |
Qt::ContextMenuPolicy | contextMenuPolicy () const |
QCursor | cursor () const |
WId | effectiveWinId () const |
void | ensurePolished () const |
Qt::FocusPolicy | focusPolicy () const |
QWidget * | focusProxy () const |
QWidget * | focusWidget () const |
const QFont & | font () const |
QFontInfo | fontInfo () const |
QFontMetrics | fontMetrics () const |
QPalette::ColorRole | foregroundRole () const |
QRect | frameGeometry () const |
QSize | frameSize () const |
const QRect & | geometry () const |
void | getContentsMargins (int *left, int *top, int *right, int *bottom) const |
QPixmap | grab (const QRect &rectangle=QRect (QPoint (0, 0), QSize (-1,-1))) |
void | grabGesture (Qt::GestureType gestureType, Qt::GestureFlags flags=Qt::GestureFlags ()) |
void | grabKeyboard () |
void | grabMouse () |
void | grabMouse (const QCursor &cursor) |
int | grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut) |
QGraphicsEffect * | graphicsEffect () const |
QGraphicsProxyWidget * | graphicsProxyWidget () const |
bool | hasEditFocus () const |
bool | hasFocus () const |
virtual bool | hasHeightForWidth () const |
bool | hasMouseTracking () const |
int | height () const |
virtual int | heightForWidth (int width) const |
Qt::InputMethodHints | inputMethodHints () const |
void | insertAction (QAction *before, QAction *action) |
void | insertActions (QAction *before, QList< QAction * > actions) |
bool | isActiveWindow () const |
bool | isAncestorOf (const QWidget *child) const |
bool | isEnabled () const |
bool | isEnabledTo (const QWidget *parent) const |
bool | isEnabledToTLW () const |
bool | isFullScreen () const |
bool | isHidden () const |
bool | isMaximized () const |
bool | isMinimized () const |
bool | isModal () const |
bool | isTopLevel () const |
bool | isVisible () const |
bool | isVisibleTo (const QWidget *parent) const |
bool | isWindow () const |
bool | isWindowModified () const |
QLayout * | layout () const |
Qt::LayoutDirection | layoutDirection () const |
QLocale | locale () const |
QPoint | mapFrom (const QWidget *parent, const QPoint &pos) const |
QPoint | mapFromGlobal (const QPoint &pos) const |
QPoint | mapFromParent (const QPoint &pos) const |
QPoint | mapTo (const QWidget *parent, const QPoint &pos) const |
QPoint | mapToGlobal (const QPoint &pos) const |
QPoint | mapToParent (const QPoint &pos) const |
QRegion | mask () const |
int | maximumHeight () const |
QSize | maximumSize () const |
int | maximumWidth () const |
int | minimumHeight () const |
QSize | minimumSize () const |
int | minimumWidth () const |
void | move (const QPoint &point) |
void | move (int x, int y) |
QWidget * | nativeParentWidget () const |
QWidget * | nextInFocusChain () const |
QRect | normalGeometry () const |
void | overrideWindowFlags (Qt::WindowFlags flags) |
QPaintEngine * | paintEngine () const override |
const QPalette & | palette () const |
QWidget * | parentWidget () const |
QPoint | pos () const |
QWidget * | previousInFocusChain () const |
QRect | rect () const |
void | releaseKeyboard () |
void | releaseMouse () |
void | releaseShortcut (int id) |
void | removeAction (QAction *action) |
void | render (QPaintDevice *target, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren)) |
void | render (QPainter *painter, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren)) |
void | repaint (const QRect &rect) |
void | repaint (const QRegion ®ion) |
void | repaint (int x, int y, int w, int h) |
void | resize (const QSize &size) |
void | resize (int w, int h) |
bool | restoreGeometry (const QByteArray &geometry) |
QByteArray | saveGeometry () const |
void | scroll (int dx, int dy) |
void | scroll (int dx, int dy, const QRect &rect) |
void | setAcceptDrops (bool on) |
void | setAccessibleDescription (const QString &description) |
void | setAccessibleName (const QString &name) |
void | setAttribute (Qt::WidgetAttribute attribute, bool enable=true) |
void | setAutoFillBackground (bool enable) |
void | setBackgroundRole (QPalette::ColorRole role) |
void | setBaseSize (const QSize &size) |
void | setBaseSize (int basew, int baseh) |
void | setContentsMargins (const QMargins &margins) |
void | setContentsMargins (int left, int top, int right, int bottom) |
void | setContextMenuPolicy (Qt::ContextMenuPolicy policy) |
void | setCursor (const QCursor &cursor) |
void | setEditFocus (bool enable) |
void | setFixedHeight (int h) |
void | setFixedSize (const QSize &size) |
void | setFixedSize (int w, int h) |
void | setFixedWidth (int w) |
void | setFocus (Qt::FocusReason reason) |
void | setFocusPolicy (Qt::FocusPolicy policy) |
void | setFocusProxy (QWidget *widget) |
void | setFont (const QFont &font) |
void | setForegroundRole (QPalette::ColorRole role) |
void | setGeometry (const QRect &rect) |
void | setGeometry (int x, int y, int w, int h) |
void | setGraphicsEffect (QGraphicsEffect *effect) |
void | setInputMethodHints (Qt::InputMethodHints hints) |
void | setLayout (QLayout *layout) |
void | setLayoutDirection (Qt::LayoutDirection direction) |
void | setLocale (const QLocale &locale) |
void | setMask (const QBitmap &bitmap) |
void | setMask (const QRegion ®ion) |
void | setMaximumHeight (int maxh) |
void | setMaximumSize (const QSize &size) |
void | setMaximumSize (int maxw, int maxh) |
void | setMaximumWidth (int maxw) |
void | setMinimumHeight (int minh) |
void | setMinimumSize (const QSize &size) |
void | setMinimumSize (int minw, int minh) |
void | setMinimumWidth (int minw) |
void | setMouseTracking (bool enable) |
void | setPalette (const QPalette &palette) |
void | setParent (QWidget *parent) |
void | setParent (QWidget *parent, Qt::WindowFlags flags) |
void | setShortcutAutoRepeat (int id, bool enable=true) |
void | setShortcutEnabled (int id, bool enable=true) |
void | setSizeIncrement (const QSize &size) |
void | setSizeIncrement (int w, int h) |
void | setSizePolicy (QSizePolicy policy) |
void | setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical) |
void | setStatusTip (const QString &data) |
void | setStyle (QStyle *style) |
void | setToolTip (const QString &data) |
void | setToolTipDuration (int msec) |
void | setUpdatesEnabled (bool enable) |
void | setWhatsThis (const QString &str) |
void | setWindowFilePath (const QString &filePath) |
void | setWindowFlags (Qt::WindowFlags flags) |
void | setWindowIcon (const QIcon &icon) |
void | setWindowModality (Qt::WindowModality windowModality) |
void | setWindowOpacity (qreal level) |
void | setWindowRole (const QString &role) |
void | setWindowState (Qt::WindowStates windowState) |
QSize | size () const |
QSize | sizeIncrement () const |
QSizePolicy | sizePolicy () const |
void | stackUnder (QWidget *widget) |
QString | statusTip () const |
QStyle * | style () const |
QString | styleSheet () const |
bool | testAttribute (Qt::WidgetAttribute attribute) const |
QString | toolTip () const |
int | toolTipDuration () const |
QWidget * | topLevelWidget () const |
bool | underMouse () const |
void | ungrabGesture (Qt::GestureType gestureType) |
void | unsetCursor () |
void | unsetLayoutDirection () |
void | unsetLocale () |
void | update (const QRect &rect) |
void | update (const QRegion ®ion) |
void | update (int x, int y, int w, int h) |
void | updateGeometry () |
bool | updatesEnabled () const |
QRegion | visibleRegion () const |
QString | whatsThis () const |
int | width () const |
QWidget * | window () const |
QString | windowFilePath () const |
Qt::WindowFlags | windowFlags () const |
QWindow * | windowHandle () const |
QIcon | windowIcon () const |
Qt::WindowModality | windowModality () const |
qreal | windowOpacity () const |
QString | windowRole () const |
Qt::WindowStates | windowState () const |
QString | windowTitle () const |
Qt::WindowType | windowType () const |
WId | winId () const |
int | x () const |
int | y () const |
Public Methods inherited from QObject | |
QObject (QObject *parent=nullptr) | |
~QObject () | |
bool | blockSignals (bool block) |
const QList< QObject * > & | children () const |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
template<class T > | |
QList< T > | findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
bool | inherits (const QString &className) const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const |
bool | isWindowType () const |
void | killTimer (int id) |
const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | property (const QString &name) const |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const QString &name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
QThread * | thread () const |
Public Methods inherited from QPaintDevice | |
virtual | ~QPaintDevice () |
int | colorCount () const |
int | depth () const |
int | devicePixelRatio () const |
qreal | devicePixelRatioF () const |
int | height () const |
int | heightMM () const |
int | logicalDpiX () const |
int | logicalDpiY () const |
bool | paintingActive () const |
int | physicalDpiX () const |
int | physicalDpiY () const |
int | width () const |
int | widthMM () const |
Protected Methods | |
void | changeEvent (QEvent *event) override |
void | contextMenuEvent (QContextMenuEvent *event) override |
void | focusInEvent (QFocusEvent *event) override |
void | focusOutEvent (QFocusEvent *event) override |
void | hideEvent (QHideEvent *event) override |
void | initStyleOption (QStyleOptionComboBox *option) const |
void | inputMethodEvent (QInputMethodEvent *event) override |
void | keyPressEvent (QKeyEvent *event) override |
void | keyReleaseEvent (QKeyEvent *event) override |
void | mousePressEvent (QMouseEvent *event) override |
void | mouseReleaseEvent (QMouseEvent *event) override |
void | paintEvent (QPaintEvent *event) override |
void | resizeEvent (QResizeEvent *event) override |
void | showEvent (QShowEvent *event) override |
void | wheelEvent (QWheelEvent *event) override |
Protected Methods inherited from QWidget | |
virtual void | actionEvent (QActionEvent *event) |
virtual void | closeEvent (QCloseEvent *event) |
void | create (WId window=0, bool initializeWindow=true, bool destroyOldWindow=true) |
void | destroy (bool destroyWindow=true, bool destroySubWindows=true) |
virtual void | dragEnterEvent (QDragEnterEvent *event) |
virtual void | dragLeaveEvent (QDragLeaveEvent *event) |
virtual void | dragMoveEvent (QDragMoveEvent *event) |
virtual void | dropEvent (QDropEvent *event) |
virtual void | enterEvent (QEvent *event) |
bool | event (QEvent *event) override |
bool | focusNextChild () |
virtual bool | focusNextPrevChild (bool next) |
bool | focusPreviousChild () |
void | initPainter (QPainter *painter) const override |
virtual void | leaveEvent (QEvent *event) |
int | metric (PaintDeviceMetric metric) const override |
virtual void | mouseDoubleClickEvent (QMouseEvent *event) |
virtual void | mouseMoveEvent (QMouseEvent *event) |
virtual void | moveEvent (QMoveEvent *event) |
virtual bool | nativeEvent (const QByteArray &eventType, void *message, long *result) |
virtual void | tabletEvent (QTabletEvent *event) |
Protected Methods inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signalMethod) const |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signalMethod) const |
bool | isSignalConnected (const QMetaMethod &signalMethod) const |
int | receivers (const QString &signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Protected Methods inherited from QPaintDevice | |
QPaintDevice () | |
Additional Inherited Members | |
Public Typedefs inherited from QWidget | |
using | RenderFlags = QFlags< RenderFlag > |
Static Public Methods inherited from QWidget | |
static QWidget * | createWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag) |
static QWidget * | find (WId id) |
static QWidget * | keyboardGrabber () |
static QWidget * | mouseGrabber () |
static void | setTabOrder (QWidget *firstWidget, QWidget *secondWidget) |
Static Public Methods inherited from QObject | |
static bool | connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ()) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...)) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod) |
static QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
Protected Slots inherited from QWidget | |
void | updateMicroFocus () |
Related Functions inherited from QWidget | |
QWidgetList | |
WId | |
Related Functions inherited from QObject | |
T | qobject_cast (QObject *object) |
QObjectList | |
The QComboBox widget is a combined button and popup list. This class 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.
Information in a combobox may be edited allowing the user to modify each item in the list. Comboboxes can contain pixmaps as well as strings; the insertItem() and setItemText() methods are suitably overloaded. The methods clearEditText() is used to clear the displayed string without changing the actual combobox content.
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 the value in the list. If the value is inserted it can be added in one of several different locations in the list. The default policy is insertAtBottom, which can be changed 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 architecture. The default is a QStandardItemModel for storing the items and a QListView to display the drop down combo box. The methods model() and view() can be used to return the current model and view objects. To set a new model or view call setModel() or setView().
The methods setItemText() and itemText() are used to set and get the text which will be displayed to the user. A icon can be set or retrieved using setItemIcon and itemIcon().
The methods setItemData() and itemData() are used to set a QVariant value for a specific user role. The roles are used by the view to indicate to the model which type of data it needs.
Since multiple selections in a combo box are not allowed, you can not alter the QAbstractItemView::SelectionMode of the view() using setSelectionMode().
This enum specifies what the QComboBox should do when a new string is entered by the user.
Constant | Value | Description |
---|---|---|
QComboBox::NoInsert | 0 | The string will not be inserted into the combobox. |
QComboBox::InsertAtTop | 1 | The string will be inserted as the first item in the combobox. |
QComboBox::InsertAtCurrent | 2 | The current item will be replaced by the string. |
QComboBox::InsertAtBottom | 3 | The string will be inserted after the last item in the combobox. |
QComboBox::InsertAfterCurrent | 4 | The string is inserted after the current item in the combobox. |
QComboBox::InsertBeforeCurrent | 5 | The string is inserted before the current item in the combobox. |
QComboBox::InsertAlphabetically | 6 | The string is inserted in the alphabetic order in the combobox. |
This enum specifies how the size hint of the QComboBox should adjust when new content is added or content changes.
Constant | Value | Description |
---|---|---|
QComboBox::AdjustToContents | 0 | The combobox will always adjust to the contents |
QComboBox::AdjustToContentsOnFirstShow | 1 | The combobox will adjust to its contents the first time it is shown. |
QComboBox::AdjustToMinimumContentsLengthWithIcon | 2 | The combobox will adjust to minimumContentsLength plus space for an icon. For performance reasons use this policy on large models. |
|
explicit |
Constructs a combobox with the given parent, using the default model QStandardItemModel.
QComboBox::~QComboBox | ( | ) |
Destroys the combobox.
|
signal |
This signal is sent when the user chooses an item in the combobox. The text from the item is passed to any connected slots. This signal is emitted even when the selected item was already the currently selected item. If you need to invoke a slot only when the selection changes, then use the signal currentIndexChanged().
|
signal |
This signal is sent when the user chooses an item in the combobox. The index of the item is passed to any connected slots. This signal is emitted even when the selected item was already the currently selected item. If you need to invoke a slot only when the selection changes, then use the signal currentIndexChanged().
|
inline |
Adds an item to the combobox with the given icon and text for the specified userData. The userData is stored in the Qt::UserRole. The item is appended to the list of existing items.
Adds an item to the combobox with the given text for the specified userData. The userData is stored in the Qt::UserRole. The item is appended to the list of existing items.
|
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.
bool QComboBox::autoCompletion | ( | ) | const |
Returns the value of the property.
Qt::CaseSensitivity QComboBox::autoCompletionCaseSensitivity | ( | ) | const |
Returns the value of the property.
|
overrideprotectedvirtual |
Reimplemented from QWidget::changeEvent()
|
slot |
Clears the combobox removing all items. If you have set an external model on the combobox this model will still be cleared when calling this method.
|
slot |
Clears the contents of the line edit used for editing in the combobox.
QCompleter * QComboBox::completer | ( | ) | const |
Returns a pointer to the QCompleter object which is used to auto complete text input for the QComboBox.
|
overrideprotectedvirtual |
Reimplemented from QWidget::contextMenuEvent()
int QComboBox::count | ( | ) | const |
Returns the value of the property.
QVariant QComboBox::currentData | ( | int | role = Qt::UserRole | ) | const |
Returns the value of the property.
int QComboBox::currentIndex | ( | ) | const |
Returns the value of the property.
|
signal |
This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. The text represents the item which is now selected.
|
signal |
This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. The item index is passed or -1 if the combobox becomes empty or the currentIndex was reset.
QString QComboBox::currentText | ( | ) | const |
Returns the value of the property.
|
signal |
Sets the value of the property to str.
bool QComboBox::duplicatesEnabled | ( | ) | const |
Returns the value of the property.
|
signal |
This signal is emitted when the text in the combobox's line edit widget is changed. The new text is specified by text.
|
override |
Reimplemented from QWidget::event()
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.
|
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.
|
overrideprotectedvirtual |
Reimplemented from QWidget::focusInEvent()
|
overrideprotectedvirtual |
Reimplemented from QWidget::focusOutEvent()
bool QComboBox::hasFrame | ( | ) | const |
Returns the value of the property.
|
overrideprotectedvirtual |
Reimplemented from QWidget::hideEvent()
|
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.
|
signal |
This signal is sent when an item in the combobox popup list is highlighted by the user. The item's text is passed.
|
signal |
This signal is sent when an item in the combobox popup list is highlighted by the user. The item's index is passed.
QSize QComboBox::iconSize | ( | ) | const |
Returns the value of the property.
|
protected |
Initialize option with the values from this QComboBox. This method is useful for subclasses when they need a QStyleOptionComboBox, but do not want to fill in all the information themselves.
|
overrideprotectedvirtual |
Reimplemented from QWidget::inputMethodEvent()
|
overridevirtual |
Reimplemented from QWidget::inputMethodQuery()
void QComboBox::insertItem | ( | int | index, |
const QIcon & | icon, | ||
const QString & | text, | ||
const QVariant & | userData = QVariant() |
||
) |
Inserts a new item with the values for icon, text and userData at the specified index position in the current QComboBox. The userData is stored in the Qt::UserRole.
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.
|
inline |
Inserts a new item with the values for text and userData at the specified index position in the current QComboBox. The userData is stored in the Qt::UserRole.
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.
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.
InsertPolicy QComboBox::insertPolicy | ( | ) | const |
Returns the value of the property.
void QComboBox::insertSeparator | ( | int | index | ) |
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.
bool QComboBox::isEditable | ( | ) | const |
Returns the value of the property.
QVariant QComboBox::itemData | ( | int | index, |
int | role = Qt::UserRole |
||
) | const |
Returns the data for the specified role at the given index in the combobox. If there is no data then a QVariant with the data type QVariant::Invalid is returned.
QAbstractItemDelegate * QComboBox::itemDelegate | ( | ) | const |
Returns the item delegate used by the popup list view.
QIcon QComboBox::itemIcon | ( | int | index | ) | const |
Returns the icon for the given index in the combobox.
QString QComboBox::itemText | ( | int | index | ) | const |
Returns the text for the given index in the combobox.
|
overrideprotectedvirtual |
Reimplemented from QWidget::keyPressEvent()
|
overrideprotectedvirtual |
Reimplemented from QWidget::keyReleaseEvent()
QLineEdit * QComboBox::lineEdit | ( | ) | const |
Returns the line edit used to edit items in the combobox or a nullptr if there is no line edit. Only editable combo boxes have a line edit.
int QComboBox::maxCount | ( | ) | const |
Returns the value of the property.
int QComboBox::maxVisibleItems | ( | ) | const |
Returns the value of the property.
int QComboBox::minimumContentsLength | ( | ) | const |
Returns the value of the property.
|
overridevirtual |
Reimplemented from QWidget::minimumSizeHint()
QAbstractItemModel * QComboBox::model | ( | ) | const |
Returns the model used by the combobox.
int QComboBox::modelColumn | ( | ) | const |
Returns the value of the property.
|
overrideprotectedvirtual |
Reimplemented from QWidget::mousePressEvent()
|
overrideprotectedvirtual |
Reimplemented from QWidget::mouseReleaseEvent()
|
overrideprotectedvirtual |
Reimplemented from QWidget::paintEvent()
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 method does nothing if index is out of range.
|
overrideprotectedvirtual |
Reimplemented from QWidget::resizeEvent()
QModelIndex QComboBox::rootModelIndex | ( | ) | const |
Returns the root model item index for the items in the combobox.
void QComboBox::setAutoCompletion | ( | bool | enable | ) |
Sets the value of the property to enable.
void QComboBox::setAutoCompletionCaseSensitivity | ( | Qt::CaseSensitivity | sensitivity | ) |
Sets the value of the property to sensitivity.
void QComboBox::setCompleter | ( | QCompleter * | completer | ) |
Sets the completer object which is used when editing text in a QComboBox. If the completer is a nullptr the auto completion will be disabled.
The QComboBox must be set with the editable property enabled before calling this method, otherwise the QCompleter will be ignored.
|
slot |
Sets the value of the property to index.
|
slot |
Sets the value of the property to text.
void QComboBox::setDuplicatesEnabled | ( | bool | enable | ) |
Sets the value of the property to enable.
void QComboBox::setEditable | ( | bool | editable | ) |
Sets the value of the property to editable.
When a QComboBox is set as editable, a QCompleter which performs case insensitive inline completion is automatically created.
|
slot |
Sets the text in the combobox's text edit.
void QComboBox::setFrame | ( | bool | enable | ) |
Sets the value of the property to enable.
void QComboBox::setIconSize | ( | const QSize & | size | ) |
Sets the value of the property to size.
void QComboBox::setInsertPolicy | ( | InsertPolicy | policy | ) |
Sets the value of the property to policy.
void QComboBox::setItemData | ( | int | index, |
const QVariant & | value, | ||
int | role = Qt::UserRole |
||
) |
Sets the data for the specified role at the given index in the combobox to the given value.
Any data type which is convertible to a QVariant can be passed for the value. Examples for a convertible type would be bool, int, QString, or QLocale.
void QComboBox::setItemDelegate | ( | QAbstractItemDelegate * | delegate | ) |
Sets the item delegate for the popup list view. The combobox takes ownership of the delegate.
void QComboBox::setItemIcon | ( | int | index, |
const QIcon & | icon | ||
) |
Sets the icon for the item on the given index in the combobox.
void QComboBox::setItemText | ( | int | index, |
const QString & | text | ||
) |
Sets the text for the item on the given index in the combobox.
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.
void QComboBox::setMaxCount | ( | int | max | ) |
Sets the value of the property to max.
void QComboBox::setMaxVisibleItems | ( | int | maxItems | ) |
Sets the value of the property to maxItems.
void QComboBox::setMinimumContentsLength | ( | int | characters | ) |
Sets the value of the property to characters.
void QComboBox::setModel | ( | QAbstractItemModel * | model | ) |
void QComboBox::setModelColumn | ( | int | visibleColumn | ) |
Sets the value of the property to visibleColumn.
void QComboBox::setRootModelIndex | ( | const QModelIndex & | index | ) |
Sets the root model item index for the items in the combobox.
void QComboBox::setSizeAdjustPolicy | ( | SizeAdjustPolicy | policy | ) |
Sets the value of the property to policy.
void QComboBox::setValidator | ( | const QValidator * | validator | ) |
Sets the validator to use instead of the current validator.
void QComboBox::setView | ( | QAbstractItemView * | itemView | ) |
Sets the view to be used in the combobox popup to the given itemView. The combobox takes ownership of the view.
Note: If you want to use the convenience views (like QListWidget, QTableWidget or QTreeWidget), make sure to call setModel() on the combobox with the convenience widgets model before calling this function.
|
overrideprotectedvirtual |
Reimplemented from QWidget::showEvent()
|
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 method to show a custom pop-up, make sure you call hidePopup() to reset the internal state.
SizeAdjustPolicy QComboBox::sizeAdjustPolicy | ( | ) | const |
Returns the value of the property.
|
overridevirtual |
This implementation caches the size hint to avoid resizing when the contents change dynamically. To invalidate the cached value change the sizeAdjustPolicy.
Reimplemented from QWidget::sizeHint()
Reimplemented in QFontComboBox::sizeHint()
const QValidator * QComboBox::validator | ( | ) | const |
Returns the validator that is used to constrain text input for the combobox.
QAbstractItemView * QComboBox::view | ( | ) | const |
Returns the list view used for the combobox popup.
|
overrideprotectedvirtual |
Reimplemented from QWidget::wheelEvent()
|
deprecated |
Use setCompleter() instead.
By default, this property is true.
Properties | Class Methods |
---|---|
read | autoCompletion |
write | setAutoCompletion |
designable | true |
|
deprecated |
By default, this property is Qt::CaseInsensitive.
Use setCompleter() instead. Case sensitivity of the auto completion can be changed using QCompleter::setCaseSensitivity().
Properties | Class Methods |
---|---|
read | autoCompletionCaseSensitivity |
write | setAutoCompletionCaseSensitivity |
designable | true |
|
This property holds the number of items in the combobox.
By default, for an empty combo box, this property has a value of 0.
Properties | Class Methods |
---|---|
read | count |
|
This property holds 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.
Properties | Class Methods |
---|---|
read | currentIndex |
write | setCurrentIndex |
notify | currentIndexChanged |
|
This property holds 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.
Properties | Class Methods |
---|---|
read | currentText |
write | setCurrentText |
notify | currentTextChanged |
user | true |
|
This property holds whether the user can enter duplicate items into the combobox. It is always possible to programmatically insert duplicate items into the combobox. By default, this property is false and duplicates are not allowed.
Properties | Class Methods |
---|---|
read | duplicatesEnabled |
write | setDuplicatesEnabled |
|
This property holds 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.
Properties | Class Methods |
---|---|
read | isEditable |
write | setEditable |
|
This property holds whether the combo box draws itself with a frame. If enabled (the default) the combo box draws itself inside a frame, otherwise the combo box draws itself without any frame.
Properties | Class Methods |
---|---|
read | hasFrame |
write | setFrame |
|
This property holds 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.
Properties | Class Methods |
---|---|
read | iconSize |
write | setIconSize |
|
This property holds the policy used to determine where user-inserted items should appear in the combobox. The default value is AtBottom, indicating that new items will appear at the bottom of the list of items.
Properties | Class Methods |
---|---|
read | insertPolicy |
write | setInsertPolicy |
|
This property holds the maximum number of items allowed in the combobox. 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).
Properties | Class Methods |
---|---|
read | maxCount |
write | setMaxCount |
|
This property holds the maximum allowed size on screen of the combo box, measured in items. 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.
By default, this property has a value of 10.
Properties | Class Methods |
---|---|
read | maxVisibleItems |
write | setMaxVisibleItems |
|
This property holds the minimum number of characters that should fit into the combobox. If this property is set to a positive value, the minimumSizeHint() and sizeHint() take it into account.
The default value is 0.
Properties | Class Methods |
---|---|
read | minimumContentsLength |
write | setMinimumContentsLength |
|
This property holds 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.
Properties | Class Methods |
---|---|
read | modelColumn |
write | setModelColumn |
|
This property holds the policy describing how the size of the combobox changes when the content changes.
The default value is AdjustToContentsOnFirstShow.
Properties | Class Methods |
---|---|
read | sizeAdjustPolicy |
write | setSizeAdjustPolicy |