PySide6.QtWidgets.QRubberBand¶
- class QRubberBand¶
- The - QRubberBandclass provides a rectangle or line that can indicate a selection or a boundary. More…- Synopsis¶- Methods¶- def - __init__()
- def - shape()
 - Virtual methods¶- Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - A rubber band is often used to show a new bounding area (as in a - QSplitteror a- QDockWidgetthat is undocking). Historically this has been implemented using a QPainter 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 a - QRubberBandwhenever you need to render a rubber band around a given area (or to represent a single line), then call- setGeometry(),- move()or- resize()to position and size it. A common pattern is to do this in conjunction with mouse events. For example:- def mousePressEvent(self, event): origin = event.pos() if not rubberBand: rubberBand = QRubberBand(QRubberBand.Rectangle, self) rubberBand.setGeometry(QRect(origin, QSize())) rubberBand.show() def mouseMoveEvent(self, event): rubberBand.setGeometry(QRect(origin, event.pos()).normalized()) def mouseReleaseEvent(self, event): rubberBand.hide() # determine selection, for example using QRect::intersects() # and QRect::contains(). - If you pass a parent to - QRubberBand‘s constructor, the rubber band will display only inside its parent, but stays on top of other child widgets. If no parent is passed,- QRubberBandwill act as a top-level widget.- Call - show()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 a- Rectangleor a- Line(vertical or horizontal), depending on the- shape()it was given when constructed.- class Shape¶
- This enum specifies what shape a - QRubberBandshould have. This is a drawing hint that is passed down to the style system, and can be interpreted by each- QStyle.- Constant - Description - QRubberBand.Line - A - QRubberBandcan represent a vertical or horizontal line. Geometry is still given in- rect()and the line will fill the given geometry on most styles.- QRubberBand.Rectangle - A - QRubberBandcan represent a rectangle. Some styles will interpret this as a filled (often semi-transparent) rectangle, or a rectangular outline.
 - Constructs a rubber band of shape - s, with parent- p.- By default a rectangular rubber band ( - sis- Rectangle) will use a mask, so that a small border of the rectangle is all that is visible. Some styles (e.g., native macOS) will change this and call- setWindowOpacity()to make a semi-transparent filled selection rectangle.- initStyleOption(option)¶
- Parameters:
- option – - QStyleOptionRubberBand
 
 - Initialize - optionwith the values from this- QRubberBand. This method is useful for subclasses when they need a- QStyleOptionRubberBand, but don’t want to fill in all the information themselves.- See also - Returns the shape of this rubber band. The shape can only be set upon construction.