diff options
author | Alexey Chernov <4ernov@gmail.com> | 2016-03-22 01:01:13 +0300 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dedietrich@qt.io> | 2017-06-01 17:09:21 +0000 |
commit | 8b6d6d4832ea8ed5f9857d5ddf06408ee9d0b4e0 (patch) | |
tree | 88a0566e16fba43657e84eb9b6b6406207aeea4f /src/widgets | |
parent | 46b8997b52ef8970e68c544b3a2b10b5a2333ea7 (diff) |
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 <gabriel.dedietrich@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/widgets/qcombobox.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
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<QAbstractProxyModel *>(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<QAbstractProxyModel *>(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); } } |