diff options
author | Mark Brand <mabrand@mabrand.nl> | 2012-10-13 13:41:30 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-26 15:24:00 +0200 |
commit | 84787d82ee9369b2a83c5b0568ee62ab602a5528 (patch) | |
tree | 56ba0976b2a8acc32c334d2918dd150349ffbfc2 /src/widgets/widgets/qcombobox.cpp | |
parent | 4fbdb969fb4e446eab01f27eb2c880f8d6cb9106 (diff) |
QComboBox: fix use in QDataWidgetMapper/QItemDelegate
QItemDelegate and QDataWidgetMapper use the WRITE method on the USER
property to set a value in a widget. This did not work for QComboBox
whose USER property currentText lacked a WRITE method.
This change adds the missing setter and flags it as the WRITE method.
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.
Test included.
Follow-up to 816c5540179362500dfc175b77f05abf3ef25233 which restored
currentText as the USER property.
Task-number: QTBUG-26501
Change-Id: I5f2f999e60b09728ca03ead4e28fe36d1f3ee189
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r-- | src/widgets/widgets/qcombobox.cpp | 17 |
1 files changed, 16 insertions, 1 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 { |