The layout module

Manages and positions a group of Page instances.

class PageRects(objects=None)[source]

Bases: qpageview.rectangles.Rectangles


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

Return the number of Page instances.


Return True if there are zero pages.


Sets our margins to a QMargins object.


Return our margins as a QMargins object, intialized from _margins


Sets our page margins to a QMargins object.


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


Return the page that contains the given QPoint.

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


Yield the pages touched by the given QRect.

The pages are in undefined order.


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.


Return the default width of the page.


Return the default height of the page.


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


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

fit(size, mode)[source]

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


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


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.


Compute the correct size of every Page.


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.


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.


Return the pos on the layout for the specified offset.

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


Return the pages that are to be displayed.


Return a slice object describing the current page set.


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.


Return the number of page sets.


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

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.


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

fit(layout, size, mode)[source]

Called by

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.


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

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


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]



Return a grid that would fit in the layout.