QListview: PageDown/Up infinite loop
When item.height > viewport.height, the next item is not found correctly, resulting in an infinite loop. In this case, move directly to the next item. Change-Id: I67a40a079ca9dd9189bf84ae550758c685b83d75 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 551127209e6c45fcbbd176a65ad425c47c9bc09c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
f417af638f
commit
4795514230
@ -1201,7 +1201,10 @@ QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie
|
||||
}
|
||||
return d->closestIndex(initialRect, intersectVector);
|
||||
case MovePageUp: {
|
||||
rect.moveTop(rect.top() - d->viewport->height() + 1 );
|
||||
if (rect.height() >= d->viewport->height())
|
||||
return moveCursor(QAbstractItemView::MoveUp, modifiers);
|
||||
|
||||
rect.moveTop(rect.top() - d->viewport->height() + 1);
|
||||
if (rect.top() < rect.height()) {
|
||||
rect.setTop(0);
|
||||
rect.setBottom(1);
|
||||
@ -1242,8 +1245,11 @@ QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie
|
||||
}
|
||||
return d->closestIndex(initialRect, intersectVector);
|
||||
case MovePageDown: {
|
||||
rect.moveTop(rect.top() + d->viewport->height() - 1 );
|
||||
if (rect.bottom() > contents.height() - rect.height()){
|
||||
if (rect.height() >= d->viewport->height())
|
||||
return moveCursor(QAbstractItemView::MoveDown, modifiers);
|
||||
|
||||
rect.moveTop(rect.top() + d->viewport->height() - 1);
|
||||
if (rect.bottom() > contents.height() - rect.height()) {
|
||||
rect.setTop(contents.height() - 1);
|
||||
rect.setBottom(contents.height());
|
||||
}
|
||||
|
@ -88,6 +88,7 @@ private slots:
|
||||
void moveCursor2();
|
||||
void moveCursor3();
|
||||
void moveCursor4();
|
||||
void moveCursor5();
|
||||
void indexAt();
|
||||
void clicked();
|
||||
void singleSelectionRemoveRow();
|
||||
@ -608,6 +609,26 @@ void tst_QListView::moveCursor4()
|
||||
QTRY_COMPARE(idx, model.index(actualIndex - 2, 0));
|
||||
}
|
||||
|
||||
void tst_QListView::moveCursor5()
|
||||
{
|
||||
PublicListView listView;;
|
||||
QStandardItemModel model;
|
||||
QIcon icon(QPixmap(300,300));
|
||||
model.appendRow(new QStandardItem(icon,"11"));
|
||||
model.appendRow(new QStandardItem(icon,"22"));
|
||||
model.appendRow(new QStandardItem(icon,"33"));
|
||||
listView.setModel(&model);
|
||||
listView.setGeometry(10,10,200,200);
|
||||
listView.setIconSize(QSize(300,300));
|
||||
listView.setViewMode(QListView::IconMode);
|
||||
listView.setCurrentIndex(model.index(0, 0));
|
||||
|
||||
QModelIndex idx = listView.moveCursor(PublicListView::MovePageDown, Qt::NoModifier);
|
||||
QTRY_COMPARE(idx, model.index(1, 0));
|
||||
idx = listView.moveCursor(PublicListView::MovePageUp, Qt::NoModifier);
|
||||
QTRY_COMPARE(idx, model.index(0, 0));
|
||||
}
|
||||
|
||||
class QListViewShowEventListener : public QListView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
Loading…
x
Reference in New Issue
Block a user