diff options
author | ChunLin Wang <wangchunlin@uniontech.com> | 2021-08-17 20:07:31 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-20 13:52:47 +0000 |
commit | f4093e05136a65c6812815706f0041d2b2d88a9e (patch) | |
tree | 50b9a2e4bfc98c57dd1a008c10007d03e3724806 | |
parent | 3283d6e816cf5053a43ff38406a243dda6503fd1 (diff) |
Fix QScroller::scrollTo failing in QGraphicsView with movable item
When forcing software scrolling through QScroller::scrollTo,
it will start from (0, 0). QGraphicsViewPrivate::canStartScrollingAt
should consider the locationof points, not just the flags of item.
Fixes: QTBUG-70255
Change-Id: Iebdd5568baa3bdb41c705204dadb2895cfe9c0e2
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit 9ba4c6beeff394d8526503b43ba471d82c27df9c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/widgets/graphicsview/qgraphicsview.cpp | 2 | ||||
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 847d5fd45c..c0c659e8fd 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -614,7 +614,7 @@ bool QGraphicsViewPrivate::canStartScrollingAt(const QPoint &startPos) const const QGraphicsItem *childItem = q->itemAt(startPos); - if (childItem && (childItem->flags() & QGraphicsItem::ItemIsMovable)) + if (!startPos.isNull() && childItem && (childItem->flags() & QGraphicsItem::ItemIsMovable)) return false; return QAbstractScrollAreaPrivate::canStartScrollingAt(startPos); diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index bbcef8849e..3e3a1d18a4 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -50,6 +50,7 @@ #include <QtWidgets/QBoxLayout> #include <QtWidgets/QStyle> #include <QtWidgets/QPushButton> +#include <QtWidgets/QScroller> #if QT_CONFIG(opengl) #include <QtOpenGLWidgets/QOpenGLWidget> #endif @@ -266,6 +267,7 @@ private slots: void QTBUG_5859_exposedRect(); void hoverLeave(); void QTBUG_16063_microFocusRect(); + void QTBUG_70255_scrollTo(); #ifndef QT_NO_CURSOR void QTBUG_7438_cursor(); #endif @@ -5025,5 +5027,33 @@ void tst_QGraphicsView::QTBUG_16063_microFocusRect() QCOMPARE(mfv, IMItem::mf.translated(-view.mapToScene(view.sceneRect().toRect()).boundingRect().topLeft())); } +void tst_QGraphicsView::QTBUG_70255_scrollTo() +{ + QGraphicsView view; + QGraphicsScene scene; + view.setFixedSize(200, 200); + scene.setSceneRect(0, 0, 1000, 1000); + QGraphicsRectItem item; + item.setRect(-20, -20, 40, 40); + item.setFlag(QGraphicsItem::ItemIsMovable, true); + scene.addItem(&item); + view.setScene(&scene); + view.centerOn(0, 0); + + view.show(); + QApplication::setActiveWindow(&view); + if (!QTest::qWaitForWindowExposed(&view) || !QTest::qWaitForWindowActive(&view)) + QSKIP("Failed to show and activate window"); + + QPoint point = view.mapFromScene(0, 0); + QCOMPARE(point, QPoint(0, 0)); + + QScroller::scroller(&view)->scrollTo(QPointF(0, 500), 100); + QTest::qWait(200); + + point = view.mapFromScene(0, 0); + QCOMPARE(point, QPoint(0, -500)); +} + QTEST_MAIN(tst_QGraphicsView) #include "tst_qgraphicsview.moc" |