QRubberBand Class
The QRubberBand class draws a rectangle or a line that shows a selection or a new position. More…
| Header | #include <QRubberBand> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QWidget |
List of all members, including inherited members
Public Types
| enum | Shape |
Public Functions
| QRubberBand(Shape s, QWidget *p = nullptr) | |
| ~QRubberBand() | |
| Shape | shape() const |
Reimplemented Protected Functions
| void | paintEvent(QPaintEvent *event) |
Detailed Description
A rubber band follows the mouse while the user selects an area or moves something. Give it a geometry and show it:
void Canvas::mousePressEvent(QMouseEvent *event) {
m_origin = event->pos();
m_band->setGeometry(QRect(m_origin, QSize()));
m_band->show();
}
void Canvas::mouseMoveEvent(QMouseEvent *event) {
m_band->setGeometry(QRect(m_origin, event->pos()).normalized());
}
A rubber band lets the mouse through to the widgets under it.
See also QFocusFrame.
Differences from Qt
A rubber band is a child widget: without a parent it is a window, which Nt cannot make translucent, so give it the widget it is drawn over as the parent.
Member Type Documentation
enum QRubberBand::Shape
How the rubber band is drawn.
| Constant | Description |
|---|---|
QRubberBand::Line | A filled line, such as where a splitter or a column will move to. |
QRubberBand::Rectangle | The outline of a rectangle, lightly filled, such as an area being selected. |
Member Function Documentation
QRubberBand::QRubberBand(Shape s, QWidget *p = nullptr)
Constructs a hidden rubber band of shape s in the widget p.
QRubberBand::~QRubberBand()
Destroys the rubber band.
void QRubberBand::paintEvent(QPaintEvent *event)
Reimplements QWidget::paintEvent().
Shape QRubberBand::shape() const
Returns the shape of the rubber band.