• PySide 模块
  • PySide.QtGui
  • 内容表

    上一话题

    QToolBar

    下一话题

    QTabWidget

    QRubberBand

    概要

    函数

    详细描述

    PySide.QtGui.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 PySide.QtGui.QSplitter PySide.QtGui.QDockWidget that is undocking). Historically this has been implemented using a PySide.QtGui.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 PySide.QtGui.QRubberBand whenever you need to render a rubber band around a given area (or to represent a single line), then call PySide.QtGui.QRubberBand.setGeometry() , PySide.QtGui.QRubberBand.move() or PySide.QtGui.QRubberBand.resize() to position and size it. A common pattern is to do this in conjunction with mouse events. For example:

    class Widget:
        def mousePressEvent(self, event):
            origin = event.pos()
            if not self.rubberBand:
                self.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 PySide.QtGui.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, PySide.QtGui.QRubberBand will act as a top-level widget.

    调用 PySide.QtGui.QWidget.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 PySide.QtGui.QRubberBand.shape() it was given when constructed.

    class PySide.QtGui. QRubberBand ( arg__1 [ , parent=None ] )
    参数:

    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.

    PySide.QtGui.QRubberBand. 形状

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

    常量 描述
    QRubberBand.Line A PySide.QtGui.QRubberBand can represent a vertical or horizontal line. Geometry is still given in PySide.QtGui.QWidget.rect() and the line will fill the given geometry on most styles.
    QRubberBand.Rectangle A PySide.QtGui.QRubberBand can represent a rectangle. Some styles will interpret this as a filled (often semi-transparent) rectangle, or a rectangular outline.
    PySide.QtGui.QRubberBand. initStyleOption ( option )
    参数: option PySide.QtGui.QStyleOptionRubberBand

    初始化 option 采用值来自此 PySide.QtGui.QRubberBand 。此方法对子类是有用的,当需要 PySide.QtGui.QStyleOptionRubberBand ,但不希望自己填充所有信息。

    PySide.QtGui.QRubberBand. shape ( )
    返回类型: PySide.QtGui.QRubberBand.Shape

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