summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/widgets/qcombobox.cpp17
-rw-r--r--src/widgets/widgets/qcombobox.h3
2 files changed, 18 insertions, 2 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 74b3dc77d3..27fc3f9015 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -2001,6 +2001,17 @@ void QComboBox::setCurrentIndex(int index)
d->setCurrentIndex(mi);
}
+void QComboBox::setCurrentText(const QString &text)
+{
+ if (isEditable()) {
+ setEditText(text);
+ } else {
+ const int i = findText(text);
+ if (i > -1)
+ setCurrentIndex(i);
+ }
+}
+
void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi)
{
Q_Q(QComboBox);
@@ -2034,7 +2045,11 @@ void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi)
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.
- \sa editable
+ 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.
+
+ \sa editable, setEditText()
*/
QString QComboBox::currentText() const
{
diff --git a/src/widgets/widgets/qcombobox.h b/src/widgets/widgets/qcombobox.h
index f1f1b133cb..1d0e892fd8 100644
--- a/src/widgets/widgets/qcombobox.h
+++ b/src/widgets/widgets/qcombobox.h
@@ -66,7 +66,7 @@ class Q_WIDGETS_EXPORT QComboBox : public QWidget
Q_ENUMS(SizeAdjustPolicy)
Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
Q_PROPERTY(int count READ count)
- Q_PROPERTY(QString currentText READ currentText USER true)
+ Q_PROPERTY(QString currentText READ currentText WRITE setCurrentText USER true)
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
Q_PROPERTY(int maxVisibleItems READ maxVisibleItems WRITE setMaxVisibleItems)
Q_PROPERTY(int maxCount READ maxCount WRITE setMaxCount)
@@ -211,6 +211,7 @@ public Q_SLOTS:
void clearEditText();
void setEditText(const QString &text);
void setCurrentIndex(int index);
+ void setCurrentText(const QString &text);
Q_SIGNALS:
void editTextChanged(const QString &);