Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_gui_widgets_qrubberband.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4//! [0]
5void Widget::mousePressEvent(QMouseEvent *event)
6{
7 origin = event->pos();
8 if (!rubberBand)
9 rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
10 rubberBand->setGeometry(QRect(origin, QSize()));
11 rubberBand->show();
12}
13
14void Widget::mouseMoveEvent(QMouseEvent *event)
15{
16 rubberBand->setGeometry(QRect(origin, event->pos()).normalized());
17}
18
19void Widget::mouseReleaseEvent(QMouseEvent *event)
20{
21 rubberBand->hide();
22 // determine selection, for example using QRect::intersects()
23 // and QRect::contains().
24}
25//! [0]