QgsLayoutItemPage class

Item representing the paper in a layout.

Base classes

class QgsLayoutItem
Base class for graphical items within a QgsLayout.

Public types

enum Orientation { Portrait, Landscape }
Page orientiation.
enum UndoCommand { UndoPageSymbol = 3000 }
Page item undo commands, used for collapsing undo commands.

Public static functions

static auto create(QgsLayout* layout) -> QgsLayoutItemPage*
Returns a new page item for the specified layout.
static auto decodePageOrientation(const QString& string, bool* ok = nullptr) -> QgsLayoutItemPage::Orientation
Decodes a string representing a page orientation.

Constructors, destructors, conversion operators

QgsLayoutItemPage(QgsLayout* layout) explicit
Constructor for QgsLayoutItemPage, with the specified parent layout.

Public functions

void attemptResize(const QgsLayoutSize& size, bool includesFrame = false) override
Attempts to resize the item to a specified target size.
auto createCommand(const QString& text, int id, QUndoCommand* parent = nullptr) -> QgsAbstractLayoutUndoCommand* override
Creates a new layout undo command with the specified text and parent.
auto orientation() const -> Orientation
Returns the page orientiation.
auto pageSize() const -> QgsLayoutSize
Returns the size of the page.
void setPageSize(const QgsLayoutSize& size)
Sets the size of the page.
auto setPageSize(const QString& size, Orientation orientation = Portrait) -> bool
Sets the page size to a known page size, e.g.

Protected functions

void draw(QgsLayoutItemRenderContext& context) override
Draws the item's contents using the specified item render context.
void drawBackground(QgsRenderContext& context) override
Draws the background for the item.
void drawFrame(QgsRenderContext& context) override
Draws the frame around the item.

Enum documentation

enum QgsLayoutItemPage::Orientation

Page orientiation.

Enumerators
Portrait

Portrait orientation.

Landscape

Landscape orientation.

enum QgsLayoutItemPage::UndoCommand

Page item undo commands, used for collapsing undo commands.

Enumerators
UndoPageSymbol

Layout page symbol change.

Function documentation

static QgsLayoutItemPage* QgsLayoutItemPage::create(QgsLayout* layout)

Returns a new page item for the specified layout.

The caller takes responsibility for deleting the returned object.

static QgsLayoutItemPage::Orientation QgsLayoutItemPage::decodePageOrientation(const QString& string, bool* ok = nullptr)

Decodes a string representing a page orientation.

If specified, ok will be set to true if string could be successfully interpreted as a page orientation.

void QgsLayoutItemPage::attemptResize(const QgsLayoutSize& size, bool includesFrame = false) override

Attempts to resize the item to a specified target size.

Note that the final size of the item may not match the specified target size, as items with a fixed or minimum size will place restrictions on the allowed item size. Data defined item size overrides will also override the specified target size.

If includesFrame is true, then the size specified by size includes the item's frame.

QgsAbstractLayoutUndoCommand* QgsLayoutItemPage::createCommand(const QString& text, int id, QUndoCommand* parent = nullptr) override

Creates a new layout undo command with the specified text and parent.

The id argument can be used to specify an id number for the source event - this is used to determine whether QUndoCommand command compression can apply to the command.

Orientation QgsLayoutItemPage::orientation() const

Returns the page orientiation.

QgsLayoutSize QgsLayoutItemPage::pageSize() const

Returns the size of the page.

void QgsLayoutItemPage::setPageSize(const QgsLayoutSize& size)

Sets the size of the page.

bool QgsLayoutItemPage::setPageSize(const QString& size, Orientation orientation = Portrait)

Sets the page size to a known page size, e.g.

"A4" and orientation. The known page sizes are managed by QgsPageSizeRegistry. Valid page sizes can be retrieved via QgsPageSizeRegistry::entries(). The function returns true if size was a valid page size and the page size was changed. If false is returned then size could not be matched to a known page size.

void QgsLayoutItemPage::draw(QgsLayoutItemRenderContext& context) override protected

Draws the item's contents using the specified item render context.

Note that the context's painter has been scaled so that painter units are pixels. Use the QgsRenderContext methods to convert from millimeters or other units to the painter's units.