summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qcombobox.cpp
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2022-06-15 13:10:10 +0200
committerIvan Solovev <ivan.solovev@qt.io>2022-06-16 19:29:36 +0200
commit662184ac68803aac553921520a1b4b7b23a0633c (patch)
tree1ad0433ba777f2e243c0d6eb97426422a3d9b9e1 /src/widgets/widgets/qcombobox.cpp
parente4961afed2fc019c2a95ca582f86da2de56e351f (diff)
QComboBox: emit currentIndexChanged() and currentTextChanged() when the model is cleared
QComboBox uses QPersistentModelIndex to store the current index of the underlying model. When the model is cleared, that index is automatically invalidated, so calling QComboBoxPrivate::setCurrentIndex(QModelIndex()) does not result in signals being emitted, because we do not detect the index change. This patch uses indexBeforeChange to detect such situation and emit all necessary signals. Fixes: QTBUG-103007 Pick-to: 6.4 6.3 6.2 Change-Id: I29326830a30a17900839e8d1737a08bd940081ea Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r--src/widgets/widgets/qcombobox.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 2da6183a1e..9caac239f9 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -2135,7 +2135,11 @@ void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi)
}
updateLineEditGeometry();
}
- if (indexChanged) {
+ // If the model was reset to an empty, currentIndex will be invalidated
+ // (because it's a QPersistentModelIndex), but the index change will never
+ // be advertised. So we need an explicit check for such condition.
+ const bool modelResetToEmpty = !normalized.isValid() && indexBeforeChange != -1;
+ if (indexChanged || modelResetToEmpty) {
q->update();
_q_emitCurrentIndexChanged(currentIndex);
}