The layout module

Manages and positions a group of Page instances.

class PageRects(objects=None)[source]

Bases: qpageview.rectangles.Rectangles

get_coords(page)[source]

You should implement this method.

The result should be a four-tuple with the coordinates of the rectangle the object represents (x, y, x2, y2). These are requested only once. x should be < x2 and y should be < y2.

class PageLayout(iterable=(), /)[source]

Bases: qpageview.util.Rectangular, list

Manages page.Page instances with a list-like api.

You can iterate over the layout itself, which yields all Page instances.

The following instance attributes are used, with these class-level defaults:

zoomFactor = 1.0
dpiX = 72.0
dpiY = 72.0
rotation = Rotate_0
orientation = Vertical
alignment = Qt.AlignCenter

The layout has margins around each page, accessible via pageMargins(), and margins around the whole layout, accessible via margins(). Both have class level defaults as a tuple, but they are converted to a QMargins object for the layout instance when first accessed via the margins() and pageMargins() methods:

_margins = (6, 6, 6, 6)
_pageMargins = (0, 0, 0, 0)

spacing = 8             # pixels between pages

x = 0                   # x, y, width and height are set by update()
y = 0
width = 0
height = 0

continuousMode = True   # whether to show all pages

The actual layout is done by a LayoutEngine in the engine attribute. After having changed pages, engine or layout attributes, call update() to update the layout.

spacing = 8
zoomFactor = 1.0
dpiX = 72.0
dpiY = 72.0
rotation = 0
orientation = 2
alignment = 132
continuousMode = True
currentPageSet = 0
count()[source]

Return the number of Page instances.

empty()[source]

Return True if there are zero pages.

setMargins(margins)[source]

Sets our margins to a QMargins object.

margins()[source]

Return our margins as a QMargins object, intialized from _margins

setPageMargins(margins)[source]

Sets our page margins to a QMargins object.

pageMargins()[source]

Return our page margins as a QMargins object, intialized from _pageMargins

pageAt(point)[source]

Return the page that contains the given QPoint.

If the point is not on any page, None is returned.

pagesAt(rect)[source]

Yield the pages touched by the given QRect.

The pages are in undefined order.

nearestPageAt(point)[source]

Return the page at the shortest distance from the given point.

The returned page does not contain the point. (Use pageAt() for that.) If there are no pages outside the point, None is returned.

defaultWidth(page)[source]

Return the default width of the page.

defaultHeight(page)[source]

Return the default height of the page.

widestPage()[source]

Return the page with the largest default width, if any.

highestPage()[source]

Return the page with the largest default height, if any.

fit(size, mode)[source]

Fits the layout in the given size (QSize) and ViewMode.

zoomsToFit()[source]

Return True if the layout engine changes the zoomFactor to fit.

update()[source]

Compute the size of all pages and updates their positions. Finally set our own size.

You should call this after having added or deleted pages or after having changed the scale, dpi, zoom factor, spacing or margins.

This function returns True if the total geometry has changed.

updatePageSizes()[source]

Compute the correct size of every Page.

computeGeometry()[source]

Return the total geometry (position and size) of the layout.

In most cases the implementation of this method is sufficient: it computes the bounding rectangle of all Pages and adds the margin.

pos2offset(pos)[source]

Return a three-tuple (index, x, y).

The index refers to a page in the layout, or nowhere if -1. The x and y refer to a spot on the page (or layout if empty) in the range 0..1. You can use it to store a certain position and restore it after changing the zoom e.g.

offset2pos(offset)[source]

Return the pos on the layout for the specified offset.

The offset is a three-tuple like returned by pos2offset().

displayPages()[source]

Return the pages that are to be displayed.

currentPageSetSlice()[source]

Return a slice object describing the current page set.

pageSets()[source]

Return a list of (count, length) tuples.

Every count is the number of page sets of that length. The list is created by the LayoutEngine.pageSets() method.

pageSetCount()[source]

Return the number of page sets.

pageSet(index)[source]

Return the page set containing page at index.

engine = <qpageview.layout.LayoutEngine object>
class LayoutEngine[source]

Bases: object

A LayoutEngine takes care of the actual layout process.

A PageLayout has its LayoutEngine in the engine attribute. Putting this functionality in a separate object makes it easier to alter the behaviour of a layout without changing all the user-set options and added Pages.

The default implementation of LayoutEngine puts pages in a horizontal or vertical row.

You can override grid() to implement a different behaviour, and you can override pageSets() to get a different behaviour in non-continuous mode.

If there are multiple rows or columns, every row is as high as the highest page it contains, and every column is as wide as its widest page. You can set the attributes evenWidths and/or evenHeights to True if you want all columns to have the same width, and/or respectively, the rows the same height.

zoomToFit = True
orientation = None
evenWidths = False
evenHeights = False
grid(layout)[source]

Return a three-tuple (ncols, nrows, prepend).

ncols is the number of columns the layout will contain, nrows the number of rows; and prepend if the number of empty positions that the layout wants, when the first row has less pages.

pages(layout, ncols, nrows, prepend=0)[source]

Yield the layout’s pages in a grid: (page, (x, y)).

If prepend > 0, that number of first grid positions will remain unused. This can be used for layouts that have less pages in the first row.

dimensions(layout, ncols, nrows, prepend=0)[source]

Return two lists: columnwidths and rowheights.

The width and height are page dimensions, without page margin.

updatePagePositions(layout)[source]

Performs the positioning of the pages. Don’t call on empty layout.

fit(layout, size, mode)[source]

Called by PageLayout.fit().

zoomFitWidth(layout, width)[source]

Return the zoom factor this layout would need to fit in the width.

This method is called by fit(). The default implementation returns a suitable zoom factor for the widest Page.

zoomFitHeight(layout, height)[source]

Return the zoom factor this layout would need to fit in the height.

This method is called by fit(). The default implementation returns a suitable zoom factor for the highest Page.

pageSets(count)[source]

Return a list of (count, length) tuples.

Every count is the number of page sets of that length. When the layout is in non-continuous mode, it displays only a single page set at a time. For most layout engines, a page set is just one Page, but for column- based layouts other values make sense.

class RowLayoutEngine[source]

Bases: qpageview.layout.LayoutEngine

A layout engine that orders pages in rows.

Additional instance attributes:

pagesPerRow = 2, the number of pages to display in a row pagesFirstRow = 1, the number of pages to display in the first row fitAllColumns = True, whether “fit width” uses all columns

In non-continuous mode, this layout engine displayes a row of pages together. The orientation layout attribute is ignored in this layout engine.

pagesPerRow = 2
pagesFirstRow = 1
fitAllColumns = True
orientation = 1
pageSets(count)[source]

Return a list of (count, length) tuples respecting our column settings.

grid(layout)[source]

Return (ncols, nrows, prepend).

Takes into account the pagesPerRow and pagesFirstRow instance variables. If desired, prepends empty positions so the first row contains less pages than the column width.

zoomFitWidth(layout, width)[source]

Reimplemented to respect the fitAllColumns setting.

class RasterLayoutEngine[source]

Bases: qpageview.layout.LayoutEngine

A layout engine that aligns the pages in a grid.

This layout does not zoom to fit, but changes the number of columns and rows according to the available space. FitBoth is handled like FitWidth.

zoomToFit = False
fit(layout, size, mode)[source]

Reimplemented.

grid(layout)[source]

Return a grid that would fit in the layout.