
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQRubberBand class provides a rectangle or line that can indicate a selection or a boundary.More...
| Header: | #include <QRubberBand> |
| Inherits: | QWidget |
| enum | Shape { Line, Rectangle } |
| QRubberBand(Shape s, QWidget * p = 0) | |
| ~QRubberBand() | |
| void | move(int x, int y) |
| void | move(const QPoint & p) |
| void | resize(int width, int height) |
| void | resize(const QSize & size) |
| void | setGeometry(const QRect & rect) |
| void | setGeometry(int x, int y, int width, int height) |
| Shape | shape() const |
| void | initStyleOption(QStyleOptionRubberBand * option) const |
| virtual void | changeEvent(QEvent * e) |
| virtual bool | event(QEvent * e) |
| virtual void | moveEvent(QMoveEvent *) |
| virtual void | paintEvent(QPaintEvent *) |
| virtual void | resizeEvent(QResizeEvent *) |
| virtual void | showEvent(QShowEvent * e) |
TheQRubberBand class provides a rectangle or line that can indicate a selection or a boundary.
A rubber band is often used to show a new bounding area (as in aQSplitter or aQDockWidget that is undocking). Historically this has been implemented using aQPainter and XOR, but this approach doesn't always work properly since rendering can happen in the window below the rubber band, but before the rubber band has been "erased".
You can create aQRubberBand whenever you need to render a rubber band around a given area (or to represent a single line), then callsetGeometry(),move() orresize() to position and size it. A common pattern is to do this in conjunction with mouse events. For example:
void Widget::mousePressEvent(QMouseEvent*event){ origin= event->pos();if (!rubberBand) rubberBand=newQRubberBand(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().}
If you pass a parent toQRubberBand's constructor, the rubber band will display only inside its parent, but stays on top of other child widgets. If no parent is passed,QRubberBand will act as a top-level widget.
Callshow() to make the rubber band visible; also when the rubber band is not a top-level. Hiding or destroying the widget will make the rubber band disappear. The rubber band can be aRectangle or aLine (vertical or horizontal), depending on theshape() it was given when constructed.
This enum specifies what shape aQRubberBand should have. This is a drawing hint that is passed down to the style system, and can be interpreted by eachQStyle.
| Constant | Value | Description |
|---|---|---|
QRubberBand::Line | 0 | AQRubberBand can represent a vertical or horizontal line. Geometry is still given inrect() and the line will fill the given geometry on most styles. |
QRubberBand::Rectangle | 1 | AQRubberBand can represent a rectangle. Some styles will interpret this as a filled (often semi-transparent) rectangle, or a rectangular outline. |
Constructs a rubber band of shapes, with parentp.
By default a rectangular rubber band (s isRectangle) will use a mask, so that a small border of the rectangle is all that is visible. Some styles (e.g., native Mac OS X) will change this and callQWidget::setWindowOpacity() to make a semi-transparent filled selection rectangle.
Destructor.
[virtual protected]void QRubberBand::changeEvent(QEvent * e)Reimplemented fromQWidget::changeEvent().
[virtual protected]bool QRubberBand::event(QEvent * e)Reimplemented fromQObject::event().
[protected]void QRubberBand::initStyleOption(QStyleOptionRubberBand * option) constInitializeoption with the values from thisQRubberBand. This method is useful for subclasses when they need aQStyleOptionRubberBand, but don't want to fill in all the information themselves.
See alsoQStyleOption::initFrom().
Moves the rubberband to point (x,y).
See alsoresize().
This is an overloaded function.
Moves the rubberband to pointp.
See alsoresize().
[virtual protected]void QRubberBand::moveEvent(QMoveEvent *)Reimplemented fromQWidget::moveEvent().
[virtual protected]void QRubberBand::paintEvent(QPaintEvent *)Reimplemented fromQWidget::paintEvent().
Resizes the rubberband so that its width iswidth, and its height isheight.
See alsomove().
This is an overloaded function.
Resizes the rubberband so that its new size issize.
See alsomove().
[virtual protected]void QRubberBand::resizeEvent(QResizeEvent *)Reimplemented fromQWidget::resizeEvent().
Sets the geometry of the rubber band torect, specified in the coordinate system of its parent widget.
See alsoQWidget::geometry.
This is an overloaded function.
Sets the geometry of the rubberband to the rectangle whose top-left corner lies at the point (x,y), and with dimensions specified bywidth andheight. The geometry is specified in the parent widget's coordinate system.
Returns the shape of this rubber band. The shape can only be set upon construction.
[virtual protected]void QRubberBand::showEvent(QShowEvent * e)Reimplemented fromQWidget::showEvent().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.