From 9cf56b3e09114f65f23bb4a8062d632df94b8a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Sun, 2 Dec 2012 17:04:47 +0100 Subject: QGraphicsView - fix rubberband to expand on wheel event In SHA 51914375b615ddcac711171ac31779fea01b4323 the rubberband selection was fixed, so it followed the scene-point on mousemove. However wheelEvent could move the view - but avoid update of the rubberband (that would not be updated until next mouse-move). This patch fixes that (and generally improves rubberband behavior) since QGraphicsViewPrivate::mouseMoveEventHandler is called by replayLastMouseEvent, which is called from various places, where we need to update the rubberband (e.g scrollContentsBy). Change-Id: I1b78c27edaaecea797a2319086d7a11d437d2bd3 Reviewed-by: Andy Shaw Reviewed-by: Marc Mutz --- .../qgraphicsview/rubberband/rubberbandtest.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'tests/manual/widgets/qgraphicsview') diff --git a/tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp b/tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp index d8c2de6398..186203e7d8 100644 --- a/tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp +++ b/tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp @@ -69,11 +69,17 @@ public: protected: void mouseMoveEvent(QMouseEvent *event) { + QGraphicsView::mouseMoveEvent(event); + int rightmostInView = viewport()->mapToGlobal(viewport()->geometry().topRight()).x(); int xglobal = event->globalX(); if (xglobal > rightmostInView) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 10); - QGraphicsView::mouseMoveEvent(event); + + int bottomPos = viewport()->mapToGlobal(viewport()->geometry().bottomRight()).y(); + int yglobal = event->globalY(); + if (yglobal > bottomPos) + verticalScrollBar()->setValue(verticalScrollBar()->value() + 10); } }; @@ -82,17 +88,18 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); MyGraphicsView v; - QGraphicsScene s(0.0, 0.0, 10000.0, 100.0); + QGraphicsScene s(0.0, 0.0, 5000.0, 5000.0); v.setScene(&s); v.setInteractive(true); v.setRubberBandSelectionMode(Qt::IntersectsItemBoundingRect); s.addRect( (qreal) 0.0, 0.0, 1000.0, 50.0, QPen(),QBrush(QColor(0,0,255))); - for (int u = 0; u < 100; ++u) { - MyGraphicsItem *item = new MyGraphicsItem(); - item->setRect(QRectF(u * 100, 50.0, 50.0, 20.0)); - s.addItem(item); - } + for (int u = 0; u < 100; ++u) + for (int v = 0; v < 100; ++v) { + MyGraphicsItem *item = new MyGraphicsItem(); + item->setRect(QRectF(v * 80.0, u * 80.0, 50.0, 20.0)); + s.addItem(item); + } v.show(); app.exec(); return 0; -- cgit v1.2.3