From 212b7614e1afce5a3cfc03b481784ff1d2a1aa01 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 30 Nov 2021 19:26:38 +0100 Subject: QListView: fix a broken qBound If a QListView's model is reset to an empty one, its columnCount() below the root is going to be 0. Therefore, the code was doing a qBound(0, d->column, -1) which is meaningless (high < low). Instead, do the two logical operations explicitly: first do an upper bound on d->column (using qMin) and then lower bound the result by 0 (using qMax). The code worked by chance, because 0 was eventually the correct number to use as a bound for d->column. Change-Id: Ic32077cdab01eaa715137c05ed1f9d66c8eb2f67 Reviewed-by: Volker Hilsheimer --- src/widgets/itemviews/qlistview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 0dba849711..4dd7365113 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -690,7 +690,7 @@ void QListView::reset() void QListView::setRootIndex(const QModelIndex &index) { Q_D(QListView); - d->column = qBound(0, d->column, d->model->columnCount(index) - 1); + d->column = qMax(0, qMin(d->column, d->model->columnCount(index) - 1)); QAbstractItemView::setRootIndex(index); // sometimes we get an update before reset() is called d->clear(); -- cgit v1.2.3