summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dist/changes-5.1.04
-rw-r--r--src/widgets/graphicsview/qgraphicsview.cpp23
-rw-r--r--src/widgets/graphicsview/qgraphicsview.h1
-rw-r--r--tests/manual/widgets/qgraphicsview/rubberband/rubberbandtest.cpp37
4 files changed, 61 insertions, 4 deletions
diff --git a/dist/changes-5.1.0 b/dist/changes-5.1.0
index fdce43650e..d8ac4efe2f 100644
--- a/dist/changes-5.1.0
+++ b/dist/changes-5.1.0
@@ -82,7 +82,11 @@ QtNetwork
-
+QtWidgets
+---------
+- QGraphicsView:
+ * Added function rubberBandRect()
****************************************************************************
* Database Drivers *
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp
index 9c04a3c193..741d6658cc 100644
--- a/src/widgets/graphicsview/qgraphicsview.cpp
+++ b/src/widgets/graphicsview/qgraphicsview.cpp
@@ -1496,7 +1496,7 @@ void QGraphicsView::setDragMode(DragMode mode)
The default value is Qt::IntersectsItemShape; all items whose shape
intersects with or is contained by the rubber band are selected.
- \sa dragMode, items()
+ \sa dragMode, items(), rubberBandRect()
*/
Qt::ItemSelectionMode QGraphicsView::rubberBandSelectionMode() const
{
@@ -1508,6 +1508,27 @@ void QGraphicsView::setRubberBandSelectionMode(Qt::ItemSelectionMode mode)
Q_D(QGraphicsView);
d->rubberBandSelectionMode = mode;
}
+
+/*!
+ \since 5.1
+ This functions returns the current rubber band area (in viewport coordinates) if the user
+ is currently doing an itemselection with rubber band. When the user is not using the
+ rubber band this functions returns (a null) QRectF().
+
+ Notice that part of this QRect can be outise the visual viewport. It can e.g
+ contain negative values.
+
+ \sa rubberBandSelectionMode
+*/
+
+QRect QGraphicsView::rubberBandRect() const
+{
+ Q_D(const QGraphicsView);
+ if (d->dragMode != QGraphicsView::RubberBandDrag || !d->sceneInteractionAllowed || !d->rubberBanding)
+ return QRect();
+
+ return d->rubberBandRect;
+}
#endif
/*!
diff --git a/src/widgets/graphicsview/qgraphicsview.h b/src/widgets/graphicsview/qgraphicsview.h
index 565e89995f..a2981aec27 100644
--- a/src/widgets/graphicsview/qgraphicsview.h
+++ b/src/widgets/graphicsview/qgraphicsview.h
@@ -146,6 +146,7 @@ public:
#ifndef QT_NO_RUBBERBAND
Qt::ItemSelectionMode rubberBandSelectionMode() const;
void setRubberBandSelectionMode(Qt::ItemSelectionMode mode);
+ QRect rubberBandRect() const;
#endif
CacheMode cacheMode() const;
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;
}