diff options
author | Thorbjørn Lund Martsum <tmartsum@gmail.com> | 2012-12-10 08:16:31 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-26 13:31:45 +0100 |
commit | c56f73cc1e8f4a0a2d55d713b152548efcc595aa (patch) | |
tree | 1648a6643c5c9e210a5297a0d344a7e1fb42aa7b /tests/manual | |
parent | 932c50c015fe416354b08cea50581fa5fdfee86e (diff) |
QGraphicsView - add function to get RubberBand rect
In many situations it is handy to know the rubberband rect.
There are many situations where we want to show something
related to the rubberband.
Regardless how that is done the rubberband area is needed.
(Not having this is a flaw that can force people to do make
a customized rubberband just to get this information)
Change-Id: Ia854db4c0022b6a97b150af2b4bb78fd5e974991
Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp b/tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp index 186203e7d8..85881ca67a 100644 --- a/tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp +++ b/tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp @@ -62,7 +62,7 @@ class MyGraphicsView : public QGraphicsView { public: - MyGraphicsView() : QGraphicsView() + MyGraphicsView(QWidget *w, QLabel *l) : QGraphicsView(w), rubberbandLabel(l) { setDragMode(QGraphicsView::RubberBandDrag); } @@ -80,13 +80,43 @@ protected: int yglobal = event->globalY(); if (yglobal > bottomPos) verticalScrollBar()->setValue(verticalScrollBar()->value() + 10); + updateRubberbandInfo(); } + + void mouseReleaseEvent(QMouseEvent *event) + { + QGraphicsView::mouseReleaseEvent(event); + updateRubberbandInfo(); + } + + void wheelEvent (QWheelEvent *event) + { + QGraphicsView::wheelEvent(event); + updateRubberbandInfo(); + } + + void updateRubberbandInfo() + { + QString textToShow; + QDebug s(&textToShow); + s << rubberBandRect(); + if (rubberbandLabel->text() != textToShow) + rubberbandLabel->setText(textToShow); + } + QLabel *rubberbandLabel; }; int main(int argc, char *argv[]) { QApplication app(argc, argv); - MyGraphicsView v; + + QWidget w; + w.setLayout(new QVBoxLayout); + QLabel *l = new QLabel(&w); + MyGraphicsView &v = *(new MyGraphicsView(&w, l)); + + w.layout()->addWidget(&v); + w.layout()->addWidget(l); QGraphicsScene s(0.0, 0.0, 5000.0, 5000.0); v.setScene(&s); @@ -100,7 +130,8 @@ int main(int argc, char *argv[]) item->setRect(QRectF(v * 80.0, u * 80.0, 50.0, 20.0)); s.addItem(item); } - v.show(); + + w.show(); app.exec(); return 0; } |