QComboBox: fix select all columns in the view

When the QComboBox gets a custom view with multiple columns, only the
first one is selected even the selection mode of the view is SelectRows.
The selection changes afterwards properly honor the mode though.
Therefore check for the selection mode and call setCurrentIndex() with
the appropriate flags.

Fixes: QTBUG-86776
Pick-to: 6.0
Pick-to: 5.15
Change-Id: Ieba7b9e009358e7b6e802b7847640161ec776c64
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Christian Ehrlicher 2021-01-12 20:58:05 +01:00
parent 2054f451b1
commit b3b28faf26

View File

@ -2607,8 +2607,10 @@ void QComboBox::showPopup()
#endif
// set current item and select it
view()->selectionModel()->setCurrentIndex(d->currentIndex,
QItemSelectionModel::ClearAndSelect);
QItemSelectionModel::SelectionFlags selectionMode = QItemSelectionModel::ClearAndSelect;
if (view()->selectionBehavior() == QAbstractItemView::SelectRows)
selectionMode.setFlag(QItemSelectionModel::Rows);
view()->selectionModel()->setCurrentIndex(d->currentIndex, selectionMode);
QComboBoxPrivateContainer* container = d->viewContainer();
QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt,
QStyle::SC_ComboBoxListBoxPopup, this));