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

    上一话题

    QToolBox

    下一话题

    QGraphicsView

    QAbstractScrollArea

    继承者: QGraphicsView , QDeclarativeView , QAbstractItemView , QTreeView , QHelpContentWidget , QTreeWidget , QHeaderView , QTableView , QTableWidget , QColumnView , QListView , QUndoView , QListWidget , QHelpIndexWidget , QScrollArea , QPlainTextEdit , QTextEdit , QTextBrowser , QMdiArea

    详细描述

    PySide.QtGui.QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.

    PySide.QtGui.QAbstractScrollArea is a low-level abstraction of a scrolling area. The area provides a central widget called the viewport, in which the contents of the area is to be scrolled (i.e, the visible parts of the contents are rendered in the viewport).

    Next to the viewport is a vertical scroll bar, and below is a horizontal scroll bar. When all of the area contents fits in the viewport, each scroll bar can be either visible or hidden depending on the scroll bar's Qt.ScrollBarPolicy . When a scroll bar is hidden, the viewport expands in order to cover all available space. When a scroll bar becomes visible again, the viewport shrinks in order to make room for the scroll bar.

    It is possible to reserve a margin area around the viewport, see PySide.QtGui.QAbstractScrollArea.setViewportMargins() . The feature is mostly used to place a PySide.QtGui.QHeaderView widget above or beside the scrolling area. Subclasses of PySide.QtGui.QAbstractScrollArea should implement margins.

    When inheriting PySide.QtGui.QAbstractScrollArea , you need to do the following:

    • Control the scroll bars by setting their range, value, page step, and tracking their movements.
    • Draw the contents of the area in the viewport according to the values of the scroll bars.
    • Handle events received by the viewport in PySide.QtGui.QAbstractScrollArea.viewportEvent() - notably resize events.
    • 使用 viewport->update() to update the contents of the viewport instead of PySide.QtGui.QWidget.update() 因为所有描绘操作都发生在视口中。

    With a scroll bar policy of Qt.ScrollBarAsNeeded (默认), PySide.QtGui.QAbstractScrollArea shows scroll bars when they provide a non-zero scrolling range, and hides them otherwise.

    The scroll bars and viewport should be updated whenever the viewport receives a resize event or the size of the contents changes. The viewport also needs to be updated when the scroll bars values change. The initial values of the scroll bars are often set when the area receives new contents.

    We give a simple example, in which we have implemented a scroll area that can scroll any PySide.QtGui.QWidget . We make the widget a child of the viewport; this way, we do not have to calculate which part of the widget to draw but can simply move the widget with QWidget.move() . When the area contents or the viewport size changes, we do the following:

    areaSize = viewport().size()
    widgetSize = widget.size()
    self.verticalScrollBar().setPageStep(widgetSize.height())
    self.horizontalScrollBar().setPageStep(widgetSize.width())
    self.verticalScrollBar().setRange(0, widgetSize.height() - areaSize.height())
    self.horizontalScrollBar().setRange(0, widgetSize.width() - areaSize.width())
    self.updateWidgetPosition()
    										

    When the scroll bars change value, we need to update the widget position, i.e., find the part of the widget that is to be drawn in the viewport:

    hvalue = self.horizontalScrollBar().value()
    vvalue = self.verticalScrollBar().value()
    topLeft = self.viewport().rect().topLeft()
    self.widget.move(topLeft.x() - hvalue, topLeft.y() - vvalue)
    										

    In order to track scroll bar movements, reimplement the virtual function PySide.QtGui.QAbstractScrollArea.scrollContentsBy() . In order to fine-tune scrolling behavior, connect to a scroll bar's QAbstractSlider.actionTriggered() signal and adjust the QAbstractSlider.sliderPosition as you wish.

    For convenience, PySide.QtGui.QAbstractScrollArea makes all viewport events available in the virtual PySide.QtGui.QAbstractScrollArea.viewportEvent() handler. PySide.QtGui.QWidget ‘s specialized handlers are remapped to viewport events in the cases where this makes sense. The remapped specialized handlers are: PySide.QtGui.QAbstractScrollArea.paintEvent() , PySide.QtGui.QAbstractScrollArea.mousePressEvent() , PySide.QtGui.QAbstractScrollArea.mouseReleaseEvent() , PySide.QtGui.QAbstractScrollArea.mouseDoubleClickEvent() , PySide.QtGui.QAbstractScrollArea.mouseMoveEvent() , PySide.QtGui.QAbstractScrollArea.wheelEvent() , PySide.QtGui.QAbstractScrollArea.dragEnterEvent() , PySide.QtGui.QAbstractScrollArea.dragMoveEvent() , PySide.QtGui.QAbstractScrollArea.dragLeaveEvent() , PySide.QtGui.QAbstractScrollArea.dropEvent() , PySide.QtGui.QAbstractScrollArea.contextMenuEvent() ,和 PySide.QtGui.QAbstractScrollArea.resizeEvent() .

    PySide.QtGui.QScrollArea , which inherits PySide.QtGui.QAbstractScrollArea , provides smooth scrolling for any PySide.QtGui.QWidget (i.e., the widget is scrolled pixel by pixel). You only need to subclass PySide.QtGui.QAbstractScrollArea if you need more specialized behavior. This is, for instance, true if the entire contents of the area is not suitable for being drawn on a PySide.QtGui.QWidget or if you do not want smooth scrolling.

    class PySide.QtGui. QAbstractScrollArea ( [ parent=None ] )
    参数: parent PySide.QtGui.QWidget

    Constructs a viewport.

    parent 自变量被发送给 PySide.QtGui.QWidget 构造函数。

    PySide.QtGui.QAbstractScrollArea. addScrollBarWidget ( widget , alignment )
    参数:
    PySide.QtGui.QAbstractScrollArea. cornerWidget ( )
    返回类型: PySide.QtGui.QWidget

    Returns the widget in the corner between the two scroll bars.

    By default, no corner widget is present.

    PySide.QtGui.QAbstractScrollArea. horizontalScrollBar ( )
    返回类型: PySide.QtGui.QScrollBar

    Returns the horizontal scroll bar.

    PySide.QtGui.QAbstractScrollArea. horizontalScrollBarPolicy ( )
    返回类型: PySide.QtCore.Qt.ScrollBarPolicy

    This property holds the policy for the horizontal scroll bar.

    The default policy is Qt.ScrollBarAsNeeded .

    PySide.QtGui.QAbstractScrollArea. maximumViewportSize ( )
    返回类型: PySide.QtCore.QSize

    Returns the size of the viewport as if the scroll bars had no valid scrolling range.

    PySide.QtGui.QAbstractScrollArea. scrollBarWidgets ( alignment )
    参数: alignment PySide.QtCore.Qt.Alignment
    返回类型:
    PySide.QtGui.QAbstractScrollArea. scrollContentsBy ( dx , dy )
    参数:
    • dx PySide.QtCore.int
    • dy PySide.QtCore.int

    调用此虚拟处理程序当滚动条被移动按 dx , dy ,因此,应相应卷动视口内容。

    默认实现只需调用 PySide.QtGui.QWidget.update() on the entire PySide.QtGui.QAbstractScrollArea.viewport() , subclasses can reimplement this handler for optimization purposes, or - like PySide.QtGui.QScrollArea - to move a contents widget. The parameters dx and dy are there for convenience, so that the class knows how much should be scrolled (useful e.g. when doing pixel-shifts). You may just as well ignore these values and scroll directly to the position the scroll bars indicate.

    Calling this function in order to scroll programmatically is an error, use the scroll bars instead (e.g. by calling QScrollBar.setValue() directly).

    PySide.QtGui.QAbstractScrollArea. setCornerWidget ( widget )
    参数: widget PySide.QtGui.QWidget

    Sets the widget in the corner between the two scroll bars to be widget .

    You will probably also want to set at least one of the scroll bar modes to AlwaysOn .

    Passing 0 shows no widget in the corner.

    Any previous corner widget is hidden.

    You may call PySide.QtGui.QAbstractScrollArea.setCornerWidget() with the same widget at different times.

    All widgets set here will be deleted by the scroll area when it is destroyed unless you separately reparent the widget after setting some other corner widget (or 0).

    Any newly set widget should have no current parent.

    By default, no corner widget is present.

    PySide.QtGui.QAbstractScrollArea. setHorizontalScrollBar ( scrollbar )
    参数: scrollbar PySide.QtGui.QScrollBar

    Replaces the existing horizontal scroll bar with scrollBar , and sets all the former scroll bar's slider properties on the new scroll bar. The former scroll bar is then deleted.

    PySide.QtGui.QAbstractScrollArea already provides horizontal and vertical scroll bars by default. You can call this function to replace the default horizontal scroll bar with your own custom scroll bar.

    PySide.QtGui.QAbstractScrollArea. setHorizontalScrollBarPolicy ( arg__1 )
    参数: arg__1 PySide.QtCore.Qt.ScrollBarPolicy

    This property holds the policy for the horizontal scroll bar.

    The default policy is Qt.ScrollBarAsNeeded .

    PySide.QtGui.QAbstractScrollArea. setVerticalScrollBar ( scrollbar )
    参数: scrollbar PySide.QtGui.QScrollBar

    Replaces the existing vertical scroll bar with scrollBar , and sets all the former scroll bar's slider properties on the new scroll bar. The former scroll bar is then deleted.

    PySide.QtGui.QAbstractScrollArea already provides vertical and horizontal scroll bars by default. You can call this function to replace the default vertical scroll bar with your own custom scroll bar.

    PySide.QtGui.QAbstractScrollArea. setVerticalScrollBarPolicy ( arg__1 )
    参数: arg__1 PySide.QtCore.Qt.ScrollBarPolicy

    This property holds the policy for the vertical scroll bar.

    The default policy is Qt.ScrollBarAsNeeded .

    PySide.QtGui.QAbstractScrollArea. setViewport ( widget )
    参数: widget PySide.QtGui.QWidget

    Sets the viewport to be the given widget PySide.QtGui.QAbstractScrollArea will take ownership of the given widget .

    widget is 0, PySide.QtGui.QAbstractScrollArea will assign a new PySide.QtGui.QWidget instance for the viewport.

    PySide.QtGui.QAbstractScrollArea. setViewportMargins ( left , top , right , bottom )
    参数:
    • left PySide.QtCore.int
    • top PySide.QtCore.int
    • right PySide.QtCore.int
    • bottom PySide.QtCore.int

    Sets the margins around the scrolling area to left , top , right and bottom . This is useful for applications such as spreadsheets with “locked” rows and columns. The marginal space is is left blank; put widgets in the unused area.

    Note that this function is frequently called by PySide.QtGui.QTreeView and PySide.QtGui.QTableView , so margins must be implemented by PySide.QtGui.QAbstractScrollArea subclasses. Also, if the subclasses are to be used in item views, they should not call this function.

    By default all margins are zero.

    PySide.QtGui.QAbstractScrollArea. setViewportMargins ( margins )
    参数: margins PySide.QtCore.QMargins

    margins around the scrolling area. This is useful for applications such as spreadsheets with “locked” rows and columns. The marginal space is is left blank; put widgets in the unused area.

    By default all margins are zero.

    PySide.QtGui.QAbstractScrollArea. setupViewport ( 视口 )
    参数: 视口 PySide.QtGui.QWidget

    This slot is called by PySide.QtGui.QAbstractScrollArea after setViewport( 视口 ) has been called. Reimplement this function in a subclass of PySide.QtGui.QAbstractScrollArea to initialize the new 视口 before it is used.

    PySide.QtGui.QAbstractScrollArea. verticalScrollBar ( )
    返回类型: PySide.QtGui.QScrollBar

    返回垂直滚动条。

    PySide.QtGui.QAbstractScrollArea. verticalScrollBarPolicy ( )
    返回类型: PySide.QtCore.Qt.ScrollBarPolicy

    This property holds the policy for the vertical scroll bar.

    The default policy is Qt.ScrollBarAsNeeded .

    PySide.QtGui.QAbstractScrollArea. 视口 ( )
    返回类型: PySide.QtGui.QWidget

    返回视口 Widget。

    使用 QScrollArea.widget() function to retrieve the contents of the viewport widget.

    PySide.QtGui.QAbstractScrollArea. viewportEvent ( arg__1 )
    参数: arg__1 PySide.QtCore.QEvent
    返回类型: PySide.QtCore.bool

    The main event handler for the scrolling area (the PySide.QtGui.QAbstractScrollArea.viewport() widget). It handles the event specified, and can be called by subclasses to provide reasonable default behavior.

    Returns true to indicate to the event system that the event has been handled, and needs no further processing; otherwise returns false to indicate that the event should be propagated further.

    You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.

    Specialized handlers for viewport events are: PySide.QtGui.QAbstractScrollArea.paintEvent() , PySide.QtGui.QAbstractScrollArea.mousePressEvent() , PySide.QtGui.QAbstractScrollArea.mouseReleaseEvent() , PySide.QtGui.QAbstractScrollArea.mouseDoubleClickEvent() , PySide.QtGui.QAbstractScrollArea.mouseMoveEvent() , PySide.QtGui.QAbstractScrollArea.wheelEvent() , PySide.QtGui.QAbstractScrollArea.dragEnterEvent() , PySide.QtGui.QAbstractScrollArea.dragMoveEvent() , PySide.QtGui.QAbstractScrollArea.dragLeaveEvent() , PySide.QtGui.QAbstractScrollArea.dropEvent() , PySide.QtGui.QAbstractScrollArea.contextMenuEvent() ,和 PySide.QtGui.QAbstractScrollArea.resizeEvent() .