The scrollarea module

ScrollArea, that supports kinetic scrolling and other features.

class ScrollArea(parent=None, **kwds)[source]

Bases: PyQt5.QtWidgets.QAbstractScrollArea

A scroll area that supports kinetic scrolling and other features.

alignment = 132

how to align the scrolled area if smaller than the viewport (Qt.AlignCenter)

scrollupdatespersec = 50

how many scroll updates to draw per second (50, 50 is recommended).

kineticScrollingEnabled = True

whether the mouse wheel and PgUp/PgDn keys etc use kinetic scrolling (True)

draggingEnabled = True

If enabled, the user can drag the contents of the scrollarea to move it with the mouse.

setAreaSize(size)[source]

Updates the scrollbars to be able to display an area of this size.

areaSize()[source]

Return the size of the area as set by setAreaSize().

areaPos()[source]

Return the position of the area relative to the viewport.

The alignment attribute is taken into account when the area is smaller than the viewport (horizontally and/or vertically).

visibleArea()[source]

Return a rectangle describing the part of the area that is visible.

offsetToEnsureVisible(rect)[source]

Return an offset QPoint with the minimal scroll to make rect visible.

If the rect is too large, it is positioned top-left.

ensureVisible(rect, margins=None, allowKinetic=True)[source]

Performs the minimal scroll to make rect visible.

If the rect is not completely visible it is scrolled into view, adding the margins if given (a QMargins instance). If allowKinetic is False, immediately jumps to the position, otherwise scrolls smoothly (if kinetic scrolling is enabled).

scrollOffset()[source]

Return the current scroll offset.

canScrollBy(diff)[source]

Does not scroll, but return the actual distance the View would scroll.

diff is a QPoint instance.

scrollForDragging(pos)[source]

Slowly scroll the View if pos is close to the edge of the viewport.

Can be used while dragging things.

scrollTo(pos)[source]

Scroll the View to get pos (QPoint) in the top left corner (if possible).

Returns the actual distance moved.

scrollBy(diff)[source]

Scroll the View diff pixels (QPoint) in x and y direction.

Returns the actual distance moved.

kineticScrollTo(pos)[source]

Scroll the View to get pos (QPoint) in the top left corner (if possible).

Returns the actual distance the scroll area will move.

kineticScrollBy(diff)[source]

Scroll the View diff pixels (QPoint) in x and y direction.

Returns the actual distance the scroll area will move.

kineticAddDelta(diff)[source]

Add diff (QPoint) to an existing kinetic scroll.

If no scroll is active, a new one is started (like kineticScrollBy).

steadyScroll(diff)[source]

Start steadily scrolling diff (QPoint) pixels per second.

Stops automatically when the end is reached.

startScrolling(scroller)[source]

Begin a scrolling operation using the specified scroller.

stopScrolling()[source]

Stop scrolling.

isScrolling()[source]

Return True if a scrolling movement is active.

remainingScrollTime()[source]

If a kinetic scroll is active, return how many msecs the scroll wil last.

Otherwise, return 0.

isDragging()[source]

Return True if the user is dragging the background.

timerEvent(ev)[source]

Implemented to handle the scroll timer.

resizeEvent(ev)[source]

Implemented to update the scrollbars to the aera size.

mousePressEvent(ev)[source]

Implemented to handle dragging the document with the left button.

mouseMoveEvent(ev)[source]

Implemented to handle dragging the document with the left button.

mouseReleaseEvent(ev)[source]

Implemented to handle dragging the document with the left button.

wheelEvent(ev)[source]

Reimplemented to use kinetic mouse wheel scrolling if enabled.

keyPressEvent(ev)[source]

Reimplemented to use kinetic cursor movements.

class Scroller[source]

Bases: object

Abstract base class, encapsulates scrolling behaviour.

A Scroller subclass must implement the step() and finished() methods and may define additional methods.

step()[source]

Implement this method to return a QPoint for the current scrolling step.

finished()[source]

Implement this method to return True if scrolling is finished.

class SteadyScroller(speed, updates_per_second)[source]

Bases: qpageview.scrollarea.Scroller

Scrolls the area steadily n pixels per second.

step()[source]

Return a QPoint indicating the diff to scroll in this step.

If this is a QPoint(0, 0) it does not indicate that scrolling has finished. Use finished() for that.

finished()[source]

As this scroller has a constant speed, it never stops.

class KineticScroller[source]

Bases: qpageview.scrollarea.Scroller

Scrolls the area with a decreasing speed.

scrollBy(diff)[source]

Start a new kinetic scroll of the specified amount.

remainingDistance()[source]

Return the remaining distance.

remainingTicks()[source]

Return the remaining ticks of this scroll.

step()[source]

Return a QPoint indicating the diff to scroll in this step.

finished()[source]

Return True if scrolling is done.