diff options
Diffstat (limited to 'doc/src/snippets/code/src_gui_widgets_qrubberband.cpp')
-rw-r--r-- | doc/src/snippets/code/src_gui_widgets_qrubberband.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/src/snippets/code/src_gui_widgets_qrubberband.cpp b/doc/src/snippets/code/src_gui_widgets_qrubberband.cpp new file mode 100644 index 0000000..38a0dad --- /dev/null +++ b/doc/src/snippets/code/src_gui_widgets_qrubberband.cpp @@ -0,0 +1,22 @@ +//! [0] +void Widget::mousePressEvent(QMouseEvent *event) +{ + origin = event->pos(); + if (!rubberBand) + rubberBand = new QRubberBand(QRubberBand::Rectangle, this); + rubberBand->setGeometry(QRect(origin, QSize())); + rubberBand->show(); +} + +void Widget::mouseMoveEvent(QMouseEvent *event) +{ + rubberBand->setGeometry(QRect(origin, event->pos()).normalized()); +} + +void Widget::mouseReleaseEvent(QMouseEvent *event) +{ + rubberBand->hide(); + // determine selection, for example using QRect::intersects() + // and QRect::contains(). +} +//! [0] |