The highlight module

Highlight rectangular areas inside a View.

class Highlighter[source]

Bases: object

A Highlighter can draw rectangles to highlight e.g. links in a View.

An instance represents a certain type of highlighting, e.g. of a particular style. The paintRects() method is called with a list of rectangles that need to be drawn.

To implement different highlighting behaviour just inherit paintRects(). The default implementation of paintRects() uses the color attribute to get the color to use and the lineWidth (default: 2) and radius (default: 3) attributes.

lineWidth specifies the thickness in pixels of the border drawn, radius specifies the distance in pixels the border is drawn (by default with rounded corners) around the area to be highlighted. color is set to None by default, causing the paintRects method to choose the application’s palette highlight color.

lineWidth = 2
radius = 3
color = None
paintRects(painter, rects)[source]

Override this method to implement different drawing behaviour.

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

Bases: object

Mixin methods vor view.View for highlighting areas.

This mixin allows for highlighting rectangular areas on pages. You can highlight different sets of areas independently, using different Highlighter instances.

Highlighting can be set to stay on forever or to disappear after a certain amount of microseconds.

If desired, the View can be scrolled to show the highlighted areas. How the highlighting is drawn is determined by the paintRects() method of Highlighter.

defaultHighlighter()[source]

Return a default highlighter, creating it if necessary.

setDefaultHighlighter(highlighter)[source]

Set a Highlighter to use as the default highlighter.

highlightRect(areas)[source]

Return the bounding rect of the areas.

highlight(areas, highlighter=None, msec=0, scroll=False, margins=None, allowKinetic=True)[source]

Highlight the areas dict using the given or default highlighter.

The areas dict maps Page objects to lists of rectangles, where the rectangle is a QRectF() inside (0, 0, 1, 1) like the area attribute of a Link.

If the highlighter is not specified, the default highlighter will be used.

If msec > 0, the highlighting will vanish after that many microseconds.

If scroll is True, the View will be scrolled to show the areas to highlight if needed, using View.ensureVisible(highlightRect(areas), margins, allowKinetic).

clearHighlight(highlighter=None)[source]

Removes the highlighted areas of the given or default highlighter.

isHighlighting(highlighter=None)[source]

Return True if the given or default highlighter is active.

highlightUrls(urls, highlighter=None, msec=0, scroll=False, margins=None, allowKinetic=True)[source]

Convenience method highlighting the specified urls in the Document.

The urls argument is a list of urls (str); the other arguments are used for calling highlight() on the areas returned by getUrlHighlightAreas(urls).

getUrlHighlightAreas(urls)[source]

Return the areas to highlight all occurrences of the specified URLs.

The areas are found in the dictionary returned by document().urls(). URLs that are not in that dictionary are silently skipped. If there is no document set this method returns nothing.

paintEvent(ev)[source]

Paint the highlighted areas in the viewport.