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>
This commit is contained in:
parent
3283d6e816
commit
f4093e0513
@ -614,7 +614,7 @@ bool QGraphicsViewPrivate::canStartScrollingAt(const QPoint &startPos) const
|
|||||||
|
|
||||||
const QGraphicsItem *childItem = q->itemAt(startPos);
|
const QGraphicsItem *childItem = q->itemAt(startPos);
|
||||||
|
|
||||||
if (childItem && (childItem->flags() & QGraphicsItem::ItemIsMovable))
|
if (!startPos.isNull() && childItem && (childItem->flags() & QGraphicsItem::ItemIsMovable))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return QAbstractScrollAreaPrivate::canStartScrollingAt(startPos);
|
return QAbstractScrollAreaPrivate::canStartScrollingAt(startPos);
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
#include <QtWidgets/QBoxLayout>
|
#include <QtWidgets/QBoxLayout>
|
||||||
#include <QtWidgets/QStyle>
|
#include <QtWidgets/QStyle>
|
||||||
#include <QtWidgets/QPushButton>
|
#include <QtWidgets/QPushButton>
|
||||||
|
#include <QtWidgets/QScroller>
|
||||||
#if QT_CONFIG(opengl)
|
#if QT_CONFIG(opengl)
|
||||||
#include <QtOpenGLWidgets/QOpenGLWidget>
|
#include <QtOpenGLWidgets/QOpenGLWidget>
|
||||||
#endif
|
#endif
|
||||||
@ -266,6 +267,7 @@ private slots:
|
|||||||
void QTBUG_5859_exposedRect();
|
void QTBUG_5859_exposedRect();
|
||||||
void hoverLeave();
|
void hoverLeave();
|
||||||
void QTBUG_16063_microFocusRect();
|
void QTBUG_16063_microFocusRect();
|
||||||
|
void QTBUG_70255_scrollTo();
|
||||||
#ifndef QT_NO_CURSOR
|
#ifndef QT_NO_CURSOR
|
||||||
void QTBUG_7438_cursor();
|
void QTBUG_7438_cursor();
|
||||||
#endif
|
#endif
|
||||||
@ -5025,5 +5027,33 @@ void tst_QGraphicsView::QTBUG_16063_microFocusRect()
|
|||||||
QCOMPARE(mfv, IMItem::mf.translated(-view.mapToScene(view.sceneRect().toRect()).boundingRect().topLeft()));
|
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)
|
QTEST_MAIN(tst_QGraphicsView)
|
||||||
#include "tst_qgraphicsview.moc"
|
#include "tst_qgraphicsview.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user