石器时代ccitemset6

QComboBox Class | Qt Widgets 5.9
QComboBox Class
widget is a combined button and popup list.
Header: #include &QComboBox&
qmake: QT += widgets Inherits:
Inherited By:
Public Types
{ NoInsert, InsertAtTop, InsertAtCurrent, InsertAtBottom, ..., InsertAlphabetically }
{ AdjustToContents, AdjustToContentsOnFirstShow, AdjustToMinimumContentsLength, AdjustToMinimumContentsLengthWithIcon }
Properties
: const int
: const QVariant
: InsertPolicy
: SizeAdjustPolicy
59 properties inherited from
1 property inherited from
Public Functions
(QWidget *parent = Q_NULLPTR)
void (const QString &text, const QVariant &userData = QVariant())
void (const QIcon &icon, const QString &text, const QVariant &userData = QVariant())
void (const QStringList &texts)
QCompleter *() const
int () const
QVariant (int role = Qt::UserRole) const
int () const
QString () const
bool () const
int (const QVariant &data, int role = Qt::UserRole, Qt::MatchFlags flags = static_cast&Qt::MatchFlags& ( Qt::MatchExactly | Qt::MatchCaseSensitive )) const
int (const QString &text, Qt::MatchFlags flags = static_cast&Qt::MatchFlags& ( Qt::MatchExactly | Qt::MatchCaseSensitive )) const
bool () const
virtual void ()
QSize () const
void (int index, const QString &text, const QVariant &userData = QVariant())
void (int index, const QIcon &icon, const QString &text, const QVariant &userData = QVariant())
void (int index, const QStringList &list)
InsertPolicy () const
void (int index)
bool () const
QVariant (int index, int role = Qt::UserRole) const
QAbstractItemDelegate *() const
QIcon (int index) const
QString (int index) const
QLineEdit *() const
int () const
int () const
int () const
QAbstractItemModel *() const
int () const
void (int index)
QModelIndex () const
void (QCompleter *completer)
void (bool enable)
void (bool editable)
void (bool)
void (const QSize &size)
void (InsertPolicy policy)
void (int index, const QVariant &value, int role = Qt::UserRole)
void (QAbstractItemDelegate *delegate)
void (int index, const QIcon &icon)
void (int index, const QString &text)
void (QLineEdit *edit)
void (int max)
void (int maxItems)
void (int characters)
void (QAbstractItemModel *model)
void (int visibleColumn)
void (const QModelIndex &index)
void (SizeAdjustPolicy policy)
void (const QValidator *validator)
void (QAbstractItemView *itemView)
virtual void ()
SizeAdjustPolicy () const
const QValidator *() const
QAbstractItemView *() const
Reimplemented Public Functions
virtual bool (QEvent *event)
virtual QVariant (Qt::InputMethodQuery query) const
virtual QSize () const
virtual QSize () const
214 public functions inherited from
32 public functions inherited from
14 public functions inherited from
Public Slots
void (int index)
void (const QString &text)
void (const QString &text)
19 public slots inherited from
1 public slot inherited from
void (int index)
void (const QString &text)
void (int index)
void (const QString &text)
void (const QString &text)
void (const QString &text)
void (int index)
void (const QString &text)
3 signals inherited from
2 signals inherited from
Protected Functions
void (QStyleOptionComboBox *option) const
Reimplemented Protected Functions
virtual void (QEvent *e)
virtual void (QContextMenuEvent *e)
virtual void (QFocusEvent *e)
virtual void (QFocusEvent *e)
virtual void (QHideEvent *e)
virtual void (QInputMethodEvent *e)
virtual void (QKeyEvent *e)
virtual void (QKeyEvent *e)
virtual void (QMouseEvent *e)
virtual void (QMouseEvent *e)
virtual void (QPaintEvent *e)
virtual void (QResizeEvent *e)
virtual void (QShowEvent *e)
virtual void (QWheelEvent *e)
35 protected functions inherited from
9 protected functions inherited from
1 protected function inherited from
Additional Inherited Members
5 static public members inherited from
11 static public members inherited from
1 protected slot inherited from
Detailed Description
widget is a combined button and popup list.
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 pixmap the () and () functions are suitably overloaded. For editable comboboxes, the function () is provided, to clear the displayed string without changing the combobox's contents.
There are two signals emitted if the current item of a combobox changes, () and (). () is always emitted regardless if the change was done programmatically or by user interaction, while () is only emitted when the change is caused by user interaction. The () signal is emitted when the user highlights an item in the combobox popup list. All three signals exist in two versions, one with a
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 () 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
but you can change this using ().
It is possible to constrain the input to an edit see (). By default, any input is accepted.
A combobox can be populated using the insert functions, () and () for example. Items can be changed with (). An item can be removed with () and all items can be removed with (). The text of the current item is returned by (), and the text of a numbered item is returned with text(). The current item can be set with (). The number of items in the combobox is returned by (); the maximum number of items can be set with (). You can allow editing using (). For editable comboboxes you can set auto-completion using () and whether or not the user can add duplicates is set with ().
for its popup list and to store its items. By default a
stores the items and a
subclass displays the popuplist. You can access the model and view directly (with () and ()), but
also provides functions to set and get item data (e.g., () and ()). You can also set a new model and view (with () and ()). For the text and icon in the combobox label, the data in the model that has the
is used. Note that you cannot alter the
of the (), e.g., by using .
See also , , , , and .
Member Type Documentation
enum QComboBox::InsertPolicy
This enum specifies what the
should do when a new string is entered by the user.
ConstantValueDescription
QComboBox::NoInsert0The string will not be inserted into the combobox.
QComboBox::InsertAtTop1The string will be inserted as the first item in the combobox.
QComboBox::InsertAtCurrent2The current item will be replaced by the string.
QComboBox::InsertAtBottom3The string will be inserted after the last item in the combobox.
QComboBox::InsertAfterCurrent4The string is inserted after the current item in the combobox.
QComboBox::InsertBeforeCurrent5The string is inserted before the current item in the combobox.
QComboBox::InsertAlphabetically6The string is inserted in the alphabetic order in the combobox.
enum QComboBox::SizeAdjustPolicy
This enum specifies how the size hint of the
should adjust when new content is added or content changes.
ConstantValueDescription
QComboBox::AdjustToContents0The combobox will always adjust to the contents
QComboBox::AdjustToContentsOnFirstShow1The combobox will adjust to its contents the first time it is shown.
QComboBox::AdjustToMinimumContentsLength2Use AdjustToContents or AdjustToContentsOnFirstShow instead.
QComboBox::AdjustToMinimumContentsLengthWithIcon3The combobox will adjust to
plus space for an icon. For performance reasons use this policy on large models.
Property Documentation
count : const int
This property holds the number of items in the combobox
By default, for an empty combo box, this property has a value of 0.
Access functions:
int count() const
currentData : const
This property holds the data for the current item
By default, for an empty combo box or a combo box in which no current item is set, this property contains an invalid .
This property was introduced in
Access functions:
QVariant currentData(int role = Qt::UserRole) const
currentIndex : int
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.
Access functions:
int currentIndex() const
void setCurrentIndex(int index)
Notifier signal:
void (int index)
void (const QString &text)
currentText :
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.
The setter setCurrentText() simply calls () if the combo box is editable. Otherwise, if there is a matching text in the list,
is set to the corresponding index.
Access functions:
QString currentText() const
void setCurrentText(const QString &text)
Notifier signal:
void (const QString &text)
duplicatesEnabled : bool
This property holds 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).
Access functions:
bool duplicatesEnabled() const
void setDuplicatesEnabled(bool enable)
editable : bool
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.
Note: When disabling the editable state, the validator and completer are removed.Access functions:
bool isEditable() const
void setEditable(bool editable)
See also .
frame : bool
This property holds whether the combo box draws itself with a frame
If enabled (the default) the combo box draws itself inside a frame, otherwise the combo box draws itself without any frame.
Access functions:
bool hasFrame() const
void setFrame(bool)
iconSize :
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 icons of smaller size are not scaled up.
Access functions:
QSize iconSize() const
void setIconSize(const QSize &size)
insertPolicy :
This property holds the policy used to determine where user-inserted items should appear in the combobox
The default value is , indicating that new items will appear at the bottom of the list of items.
Access functions:
InsertPolicy insertPolicy() const
void setInsertPolicy(InsertPolicy policy)
See also .
maxCount : int
This property holds the maximum number of items allowed in the combobox
Note: If you set the maximum number to be less then the current amount of items in the combobox, the extra items will be truncated. This also applies if you have set an external model on the combobox.By default, this property's value is derived from the highest signed integer available (typically ).
Access functions:
int maxCount() const
void setMaxCount(int max)
maxVisibleItems : int
This property holds 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
such as the Mac style or the Gtk+ Style.Access functions:
int maxVisibleItems() const
void setMaxVisibleItems(int maxItems)
minimumContentsLength : int
This property holds 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 () and () take it into account.
Access functions:
int minimumContentsLength() const
void setMinimumContentsLength(int characters)
See also .
modelColumn : int
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.
Access functions:
int modelColumn() const
void setModelColumn(int visibleColumn)
sizeAdjustPolicy :
This property holds the policy describing how the size of the combobox changes when the content changes
The default value is .
Access functions:
SizeAdjustPolicy sizeAdjustPolicy() const
void setSizeAdjustPolicy(SizeAdjustPolicy policy)
See also .
Member Function Documentation
QComboBox::QComboBox( *parent = Q_NULLPTR)
Constructs a combobox with the given parent, using the default model .
QComboBox::~QComboBox()
Destroys the combobox.
[signal] void QComboBox::activated(int index)
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 ().
Note: Signal activated is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:connect(comboBox, static_cast&void(::*)(int)&(&::activated),
[=](int index){
[signal] void QComboBox::activated(const
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 ().
Note: Signal activated is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:connect(comboBox, static_cast&void(::*)(const
&)&(&::activated),
void QComboBox::addItem(const
&text, const
&userData = QVariant())
Adds an item to the combobox with the given text, and containing the specified userData (stored in the ). The item is appended to the list of existing items.
void QComboBox::addItem(const
&icon, const
&text, const
&userData = QVariant())
Adds an item to the combobox with the given icon and text, and containing the specified userData (stored in the ). The item is appended to the list of existing items.
void QComboBox::addItems(const
Adds each of the strings in the given texts to the combobox. Each item is appended to the list of existing items in turn.
[virtual protected] void QComboBox::changeEvent( *e)
Reimplemented from ().
[slot] void QComboBox::clear()
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.
[slot] void QComboBox::clearEditText()
Clears the contents of the line edit used for editing in the combobox.
*QComboBox::completer() const
Returns the completer that is used to auto complete text input for the combobox.
This function was introduced in
See also () and .
[virtual protected] void QComboBox::contextMenuEvent( *e)
Reimplemented from ().
[signal] void QComboBox::currentIndexChanged(int index)
This signal is sent whenever the
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
was reset.
Note: Signal currentIndexChanged is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:connect(comboBox, static_cast&void(::*)(int)&(&::currentIndexChanged),
[=](int index){
This function was introduced in
Note: Notifier signal for property .
[signal] void QComboBox::currentIndexChanged(const
This signal is sent whenever the
in the combobox changes either through user interaction or programmatically. The item's text is passed.
Note: Signal currentIndexChanged is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:connect(comboBox, static_cast&void(::*)(const
&)&(&::currentIndexChanged),
This function was introduced in
Note: Notifier signal for property .
[signal] void QComboBox::currentTextChanged(const
This signal is sent whenever
changes. The new value is passed as text.
This function was introduced in
Note: Notifier signal for property .
[signal] void QComboBox::editTextChanged(const
This signal is emitted when the text in the combobox's line edit widget is changed. The new text is specified by text.
[virtual] bool QComboBox::event( *event)
Reimplemented from ().
int QComboBox::findData(const
&data, int role = Qt::UserRole,
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.
int QComboBox::findText(const
flags = static_cast&Qt::MatchFlags& ( Qt::MatchExactly | Qt::MatchCaseSensitive )) const
Returns the index of the item containing the given text; otherwise returns -1.
The flags specify how the items in the combobox are searched.
[virtual protected] void QComboBox::focusInEvent( *e)
Reimplemented from ().
[virtual protected] void QComboBox::focusOutEvent( *e)
Reimplemented from ().
[virtual protected] void QComboBox::hideEvent( *e)
Reimplemented from ().
[virtual] void QComboBox::hidePopup()
Hides the list of items in the combobox if it is currently visible and resets the internal state, so that if the custom pop-up was shown inside the reimplemented (), 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 ().
[signal] void QComboBox::highlighted(int index)
This signal is sent when an item in the combobox popup list is highlighted by the user. The item's index is passed.
Note: Signal highlighted is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:connect(comboBox, static_cast&void(::*)(int)&(&::highlighted),
[=](int index){
[signal] void QComboBox::highlighted(const
This signal is sent when an item in the combobox popup list is highlighted by the user. The item's text is passed.
Note: Signal highlighted is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:connect(comboBox, static_cast&void(::*)(const
&)&(&::highlighted),
[protected] void QComboBox::initStyleOption( *option) const
Initialize option with the values from this . This method is useful for subclasses when they need a , but don't want to fill in all the information themselves.
See also ().
[virtual protected] void QComboBox::inputMethodEvent( *e)
Reimplemented from ().
QComboBox::inputMethodQuery( query) const
Reimplemented from ().
void QComboBox::insertItem(int index, const
&text, const
&userData = QVariant())
Inserts the text and userData (stored in the ) 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 ().
void QComboBox::insertItem(int index, const
&icon, const
&text, const
&userData = QVariant())
Inserts the icon, text and userData (stored in the ) 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 ().
void QComboBox::insertItems(int index, const
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 ().
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.
This function was introduced in
See also ().
QComboBox::itemData(int index, int role = Qt::UserRole) const
Returns the data for the given role in the given index in the combobox, or QVariant::Invalid if there is no data for this role.
See also ().
*QComboBox::itemDelegate() const
Returns the item delegate used by the popup list view.
See also ().
QComboBox::itemIcon(int index) const
Returns the icon for the given index in the combobox.
See also ().
QComboBox::itemText(int index) const
Returns the text for the given index in the combobox.
See also ().
[virtual protected] void QComboBox::keyPressEvent( *e)
Reimplemented from ().
[virtual protected] void QComboBox::keyReleaseEvent( *e)
Reimplemented from ().
*QComboBox::lineEdit() const
Returns the line edit used to edit items in the combobox, or 0 if there is no line edit.
Only editable combo boxes have a line edit.
See also ().
QComboBox::minimumSizeHint() const
Reimplemented from ().
*QComboBox::model() const
Returns the model used by the combobox.
See also ().
[virtual protected] void QComboBox::mousePressEvent( *e)
Reimplemented from ().
[virtual protected] void QComboBox::mouseReleaseEvent( *e)
Reimplemented from ().
[virtual protected] void QComboBox::paintEvent( *e)
Reimplemented from ().
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.
[virtual protected] void QComboBox::resizeEvent( *e)
Reimplemented from ().
QComboBox::rootModelIndex() const
Returns the root model item index for the items in the combobox.
See also ().
void QComboBox::setCompleter( *completer)
Sets the completer to use instead of the current completer. If completer is 0, auto completion is disabled.
By default, for an editable combo box, a
that performs case insensitive inline completion is automatically created.
Note: The completer is removed when the
property becomes false.This function was introduced in
See also ().
[slot] void QComboBox::setEditText(const
Sets the text in the combobox's text edit.
void QComboBox::setItemData(int index, const
&value, int role = Qt::UserRole)
Sets the data role for the item on the given index in the combobox to the specified value.
See also ().
void QComboBox::setItemDelegate( *delegate)
Sets the item delegate for the popup list view. The combobox takes ownership of the delegate.
Warning: You should not share the same instance of a delegate between comboboxes, widget mappers or views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive the
signal, and attempt to access, modify or close an editor that has already been closed.
See also ().
void QComboBox::setItemIcon(int index, const
Sets the icon for the item on the given index in the combobox.
See also ().
void QComboBox::setItemText(int index, const
Sets the text for the item on the given index in the combobox.
See also ().
void QComboBox::setLineEdit( *edit)
Sets the line edit to use instead of the current line edit widget.
The combo box takes ownership of the line edit.
See also ().
void QComboBox::setModel( *model)
Sets the model to be model. model must not be 0. If you want to clear the contents of a model, call ().
See also () and ().
void QComboBox::setRootModelIndex(const
Sets the root model item index for the items in the combobox.
See also ().
void QComboBox::setValidator(const
*validator)
Sets the validator to use instead of the current validator.
Note: The validator is removed when the
property becomes false.See also ().
void QComboBox::setView( *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 ,
or ), make sure to call () on the combobox with the convenience widgets model before calling this function.
See also ().
[virtual protected] void QComboBox::showEvent( *e)
Reimplemented from ().
[virtual] void QComboBox::showPopup()
Displays the list of items in the combobox. If the list is empty then the no items will be shown.
If you reimplement this function to show a custom pop-up, make sure you call () to reset the internal state.
See also ().
QComboBox::sizeHint() const
Reimplemented from ().
This implementation caches the size hint to avoid resizing when the contents change dynamically. To invalidate the cached value change the .
*QComboBox::validator() const
Returns the validator that is used to constrain text input for the combobox.
See also () and .
*QComboBox::view() const
Returns the list view used for the combobox popup.
See also ().
[virtual protected] void QComboBox::wheelEvent( *e)
Reimplemented from ().
(C) 2017 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.
The documentation provided herein is licensed under the terms of the
as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd.
in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners.

我要回帖

更多关于 石器时代cc 的文章

 

随机推荐