QRubberBand Class Reference

[ QtGui module]

The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary. 更多...

继承 QWidget .

类型

方法


详细描述

The QRubberBand 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 a QSplitter QDockWidget that 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 QRubberBand whenever you need to render a rubber band around a given area (or to represent a single line), then call setGeometry (), move () 或 resize () 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 = new QRubberBand(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 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, QRubberBand will act as a top-level widget.

调用 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 Rectangle Line (vertical or horizontal), depending on the shape () it was given when constructed.


类型文档编制

QRubberBand.Shape

This enum specifies what shape a QRubberBand should have. This is a drawing hint that is passed down to the style system, and can be interpreted by each QStyle .

常量 描述
QRubberBand.Line 0 A QRubberBand can 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 1 A QRubberBand can represent a rectangle. Some styles will interpret this as a filled (often semi-transparent) rectangle, or a rectangular outline.

方法文档编制

QRubberBand.__init__ ( self , 形状 , QWidget   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a rubber band of shape s ,采用父级 p .

By default a rectangular rubber band ( s is Rectangle ) 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 call QWidget.setWindowOpacity () to make a semi-transparent filled selection rectangle.

QRubberBand.changeEvent ( self , QEvent )

重实现自 QWidget.changeEvent ().

bool QRubberBand.event ( self , QEvent   e )

重实现自 QObject.event ().

QRubberBand.initStyleOption ( self , QStyleOptionRubberBand   option )

初始化 option 采用值来自此 QRubberBand . This method is useful for subclasses when they need a QStyleOptionRubberBand , but don't want to fill in all the information themselves.

另请参阅 QStyleOption.initFrom ().

QRubberBand.move ( self , QPoint   p )

Moves the rubberband to point ( x , y ).

另请参阅 resize ().

QRubberBand.move ( self , int  ax , int  ay )

这是重载函数。

Moves the rubberband to point p .

另请参阅 resize ().

QRubberBand.moveEvent ( self , QMoveEvent )

重实现自 QWidget.moveEvent ().

QRubberBand.paintEvent ( self , QPaintEvent )

重实现自 QWidget.paintEvent ().

QRubberBand.resize ( self , int  w , int  h )

Resizes the rubberband so that its width is width ,和 its height is height .

另请参阅 move ().

QRubberBand.resize ( self , QSize   s )

这是重载函数。

Resizes the rubberband so that its new size is size .

另请参阅 move ().

QRubberBand.resizeEvent ( self , QResizeEvent )

重实现自 QWidget.resizeEvent ().

QRubberBand.setGeometry ( self , QRect   r )

Sets the geometry of the rubber band to rect , specified in the coordinate system of its parent widget.

另请参阅 QWidget.geometry .

QRubberBand.setGeometry ( self , int  ax , int  ay , int  aw , int  ah )

这是重载函数。

Sets the geometry of the rubberband to the rectangle whose top-left corner lies at the point ( x , y ), and with dimensions specified by width and height 。 geometry is specified in the parent widget's coordinate system.

形状 QRubberBand.shape ( self )

Returns the shape of this rubber band. The shape can only be set upon construction.

QRubberBand.showEvent ( self , QShowEvent )

重实现自 QWidget.showEvent ().