6.0.0-rc4Source

QRubberBand Class

The QRubberBand class draws a rectangle or a line that shows a selection or a new position. More…

Header#include <QRubberBand>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQWidget

List of all members, including inherited members

Public Types

enumShape

Public Functions

QRubberBand(Shape s, QWidget *p = nullptr)
~QRubberBand()
Shapeshape() const

Reimplemented Protected Functions

voidpaintEvent(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.

ConstantDescription
QRubberBand::LineA filled line, such as where a splitter or a column will move to.
QRubberBand::RectangleThe outline of a rectangle, lightly filled, such as an area being selected.

Member Function Documentation

[explicit] QRubberBand::QRubberBand(Shape s, QWidget *p = nullptr)

Constructs a hidden rubber band of shape s in the widget p.

[override] QRubberBand::~QRubberBand()

Destroys the rubber band.

[override, protected] void QRubberBand::paintEvent(QPaintEvent *event)

Reimplements QWidget::paintEvent().

Shape QRubberBand::shape() const

Returns the shape of the rubber band.