summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-11-30 19:26:38 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-12-06 12:28:41 +0100
commit212b7614e1afce5a3cfc03b481784ff1d2a1aa01 (patch)
tree371bfda5d69d026eeeceb133cea10defecace027 /src/widgets
parent251e84800793d3f74d7d8e7543eb5e9dba3834ad (diff)
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 <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/itemviews/qlistview.cpp2
1 files changed, 1 insertions, 1 deletions
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();