The rubberband module

Rubberband selection in a View.

class Rubberband[source]

Bases: PyQt5.QtWidgets.QWidget

A Rubberband to select a rectangular region.

A Rubberband is added to a View with view.setRubberband().

The Rubberband lets the user select a rectangular region. When the selection is changed, the selectionChanged signal is emitted, having the selection rectangle in layout coordinates as argument.

Instance variables:

showbutton (Qt.RightButton)

the button used to drag a new rectangle

dragbutton (Qt.LeftButton)

the button to alter an existing rectangle

trackSelection (False)

whether to continuously emit selectionChanged(). When True, selectionChanged() is emitted on every change, when False, the signal is only emitted when the mouse button is released.

selectionChanged
showbutton = 2
dragbutton = 1
trackSelection = False
paintEvent(self, QPaintEvent)[source]
edge(point)[source]

Return the edge where the point touches our geometry.

adjustCursor(edge)[source]

Sets the cursor shape when we are at edge.

hasSelection()[source]

Return True when there is a selection.

selection()[source]

Return our selection rectangle, relative to the view’s layout position.

selectedPages()[source]

Yield tuples (page, rect) describing the selection.

Every rect is intersected with the page rect and translated to the page’s position.

selectedPage()[source]

Returns (page, rect) if there is a selection.

If the selection contains more pages, the largest intersection is chosen. If no meaningful area is selected, (None, None) is returned.

selectedImage(resolution=None, paperColor=None)[source]

Returns an image of the selected part on a Page.

If resolution is None, the displayed size is chosen. Otherwise, the resolution is an integer, interpreted as DPI (dots per inch).

selectedText()[source]

Return the text found in the selection, as far as the pages support it.

Yield tuples (page, links) for every page in the selection.

links is a non-empty set() of Link instances on that page that intersect with the selection.

setSelection(rect)[source]

Sets the selection, the rectangle should be relative to the view’s layout position.

clearSelection()[source]

Hide ourselves and clear the selection.

scrollBy(diff)[source]

Called by the View when scrolling.

startDrag(pos, button)[source]

Start dragging the rubberband.

drag(pos)[source]

Continue dragging the rubberband, scrolling the View if necessary.

dragBy(diff)[source]

Drag by diff (QPoint).

stopDrag()[source]

Stop dragging the rubberband.

slotZoomChanged(zoom)[source]

Called when the zooming in the view changes, resizes ourselves.

eventFilter(viewport, ev)[source]

Act on events in the viewport:

  • keep on the same place when the viewport resizes

  • start dragging the selection if showbutton clicked (preventing the contextmenu if the showbutton is the right button)

  • end a drag on mousebutton release, if that button would have shown the context menu, show it on button release.

mousePressEvent(ev)[source]

Can start a new drag when we are clicked ourselves.

mouseMoveEvent(ev)[source]

Move if we are dragging; show the correct cursor shape on the edges.

mouseReleaseEvent(ev)[source]

End a self-initiated drag; if the right button was used; send a context menu event.