summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qcombobox.cpp
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2023-06-07 14:17:14 +0200
committerAxel Spoerl <axel.spoerl@qt.io>2023-06-13 13:48:05 +0200
commit9195438a5fd88c676b0fc4abd429bcffa6f97e24 (patch)
tree4897e8c25a355152529b0e0d1bbf9480d7f038e7 /src/widgets/widgets/qcombobox.cpp
parent65f09d4e10e435846b6669945e37f807de127199 (diff)
Fix no-op emission of QComboBox::currentTextChanged
currentTextChanged is emitted when the current index changes and the current text doesn't. This can be the case, if - old and new index have identical text values - an item is removed below the current index [ChangeLog][Widgets][QComboBox] emit currentTextChanged only, if currentText changes. Add a corresponding test in tst_QComboBox::currentText(). Fixes: QTBUG-113717 Pick-to: 6.6 Change-Id: I847874f0792b29a2841e50bb82d06ad496fb02c3 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r--src/widgets/widgets/qcombobox.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 33aa88fffb..32b43ed4fd 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -904,8 +904,11 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const
\fn void QComboBox::currentTextChanged(const QString &text)
\since 5.0
- This signal is sent whenever currentText changes. The new value
- is passed as \a text.
+ This signal is emitted whenever currentText changes.
+ The new value is passed as \a text.
+
+ \note It is not emitted, if currentText remains the same,
+ even if currentIndex changes.
*/
/*!
@@ -1071,7 +1074,7 @@ void QComboBoxPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIn
lineEdit->setText(text);
updateLineEditGeometry();
} else {
- emit q->currentTextChanged(text);
+ updateCurrentText(text);
}
q->update();
#if QT_CONFIG(accessibility)
@@ -1382,7 +1385,7 @@ void QComboBoxPrivate::_q_emitCurrentIndexChanged(const QModelIndex &index)
emit q->currentIndexChanged(index.row());
// signal lineEdit.textChanged already connected to signal currentTextChanged, so don't emit double here
if (!lineEdit)
- emit q->currentTextChanged(text);
+ updateCurrentText(text);
#if QT_CONFIG(accessibility)
QAccessibleValueChangeEvent event(q, text);
QAccessible::updateAccessibility(&event);
@@ -2848,6 +2851,15 @@ void QComboBoxPrivate::doHidePopup()
_q_resetButton();
}
+void QComboBoxPrivate::updateCurrentText(const QString &text)
+{
+ if (text == currentText)
+ return;
+
+ currentText = text;
+ emit q_func()->currentTextChanged(text);
+}
+
/*!
Clears the combobox, removing all items.