From 8b6d6d4832ea8ed5f9857d5ddf06408ee9d0b4e0 Mon Sep 17 00:00:00 2001 From: Alexey Chernov <4ernov@gmail.com> Date: Tue, 22 Mar 2016 01:01:13 +0300 Subject: Do its best in QComboBox to map completer's index Add additional code paths to map the index passed by QCompleter in its activated() signal in case when QCompleter's model isn't the same as QComboBox's one. Task-number: QTBUG-52027 Change-Id: I1d74037fccbe19962bb7f242aa7b1c2441aa5d54 Reviewed-by: Gabriel de Dietrich --- src/widgets/widgets/qcombobox.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 0dde839629..4a49542fdd 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -192,7 +192,21 @@ void QComboBoxPrivate::_q_completerActivated(const QModelIndex &index) if (index.isValid() && q->completer()) { QAbstractProxyModel *proxy = qobject_cast(q->completer()->completionModel()); if (proxy) { - q->setCurrentIndex(proxy->mapToSource(index).row()); + const QModelIndex &completerIndex = proxy->mapToSource(index); + int row = -1; + if (completerIndex.model() == model) { + row = completerIndex.row(); + } else { + // if QCompleter uses a proxy model to host widget's one - map again + QAbstractProxyModel *completerProxy = qobject_cast(q->completer()->model()); + if (completerProxy && completerProxy->sourceModel() == model) { + row = completerProxy->mapToSource(completerIndex).row(); + } else { + QString match = q->completer()->model()->data(completerIndex).toString(); + row = q->findText(match, matchFlags()); + } + } + q->setCurrentIndex(row); emitActivated(currentIndex); } } -- cgit v1.2.3