QPrintPreviewWidget

The QPrintPreviewWidget class provides a widget for previewing page layouts for printer output. More

Inheritance diagram of PySide6.QtPrintSupport.QPrintPreviewWidget

Synopsis

Functions

Slots

Signals

Detailed Description

QPrintPreviewDialog uses a QPrintPreviewWidget internally, and the purpose of QPrintPreviewWidget is to make it possible to embed the preview into other widgets. It also makes it possible to build a different user interface around it than the default one provided with QPrintPreviewDialog .

Using QPrintPreviewWidget is straightforward:

  1. Create the QPrintPreviewWidget

    Construct the QPrintPreviewWidget either by passing in an existing QPrinter object, or have QPrintPreviewWidget create a default constructed QPrinter object for you.

  2. Connect the paintRequested() signal to a slot.

    When the widget needs to generate a set of preview pages, a paintRequested() signal will be emitted from the widget. Connect a slot to this signal, and draw onto the QPrinter passed in as a signal parameter. Call newPage() , to start a new page in the preview.

class PySide6.QtPrintSupport.QPrintPreviewWidget(printer[, parent=None[, flags=Qt.WindowFlags()]])

PySide6.QtPrintSupport.QPrintPreviewWidget([parent=None[, flags=Qt.WindowFlags()]])

Parameters

Constructs a QPrintPreviewWidget based on printer and with parent as the parent widget. The widget flags flags are passed on to the QWidget constructor.

See also

setWindowFlags()

This is an overloaded function.

This will cause QPrintPreviewWidget to create an internal, default constructed QPrinter object, which will be used to generate the preview.

PySide6.QtPrintSupport.QPrintPreviewWidget.ViewMode

This enum is used to describe the view mode of the preview widget.

Constant

Description

QPrintPreviewWidget.SinglePageView

A mode where single pages in the preview is viewed.

QPrintPreviewWidget.FacingPagesView

A mode where the facing pages in the preview is viewed.

QPrintPreviewWidget.AllPagesView

A view mode where all the pages in the preview is viewed.

PySide6.QtPrintSupport.QPrintPreviewWidget.ZoomMode

This enum is used to describe zoom mode of the preview widget.

Constant

Description

QPrintPreviewWidget.CustomZoom

The zoom is set to a custom zoom value.

QPrintPreviewWidget.FitToWidth

This mode fits the current page to the width of the view.

QPrintPreviewWidget.FitInView

This mode fits the current page inside the view.

PySide6.QtPrintSupport.QPrintPreviewWidget.currentPage()
Return type

int

Returns the currently viewed page in the preview.

See also

setCurrentPage()

PySide6.QtPrintSupport.QPrintPreviewWidget.fitInView()

This is a convenience function and is the same as calling setZoomMode(QPrintPreviewWidget::FitInView).

PySide6.QtPrintSupport.QPrintPreviewWidget.fitToWidth()

This is a convenience function and is the same as calling setZoomMode(QPrintPreviewWidget::FitToWidth).

PySide6.QtPrintSupport.QPrintPreviewWidget.orientation()
Return type

Orientation

Returns the current orientation of the preview. This value is obtained from the QPrinter object associated with the preview.

See also

setOrientation()

PySide6.QtPrintSupport.QPrintPreviewWidget.pageCount()
Return type

int

Returns the number of pages in the preview.

PySide6.QtPrintSupport.QPrintPreviewWidget.paintRequested(printer)
Parameters

printerPySide6.QtPrintSupport.QPrinter

PySide6.QtPrintSupport.QPrintPreviewWidget.previewChanged()
PySide6.QtPrintSupport.QPrintPreviewWidget.print_()

Prints the preview to the printer associated with the preview.

PySide6.QtPrintSupport.QPrintPreviewWidget.setAllPagesViewMode()

This is a convenience function and is the same as calling setViewMode(QPrintPreviewWidget::AllPagesView).

PySide6.QtPrintSupport.QPrintPreviewWidget.setCurrentPage(pageNumber)
Parameters

pageNumber – int

Sets the current page in the preview. This will cause the view to skip to the beginning of page.

See also

currentPage()

PySide6.QtPrintSupport.QPrintPreviewWidget.setFacingPagesViewMode()

This is a convenience function and is the same as calling setViewMode(QPrintPreviewWidget::FacingPagesView).

PySide6.QtPrintSupport.QPrintPreviewWidget.setLandscapeOrientation()

This is a convenience function and is the same as calling setOrientation(QPageLayout::Landscape).

PySide6.QtPrintSupport.QPrintPreviewWidget.setOrientation(orientation)
Parameters

orientationOrientation

Sets the current orientation to orientation. This value will be set on the QPrinter object associated with the preview.

See also

orientation()

PySide6.QtPrintSupport.QPrintPreviewWidget.setPortraitOrientation()

This is a convenience function and is the same as calling setOrientation(QPageLayout::Portrait).

PySide6.QtPrintSupport.QPrintPreviewWidget.setSinglePageViewMode()

This is a convenience function and is the same as calling setViewMode(QPrintPreviewWidget::SinglePageView).

PySide6.QtPrintSupport.QPrintPreviewWidget.setViewMode(viewMode)
Parameters

viewModeViewMode

Sets the view mode to mode. The default view mode is SinglePageView .

See also

viewMode()

PySide6.QtPrintSupport.QPrintPreviewWidget.setZoomFactor(zoomFactor)
Parameters

zoomFactor – float

Sets the zoom factor of the view to factor. For example, a value of 1.0 indicates an unscaled view, which is approximately the size the view will have on paper. A value of 0.5 will halve the size of the view, while a value of 2.0 will double the size of the view.

See also

zoomFactor()

PySide6.QtPrintSupport.QPrintPreviewWidget.setZoomMode(zoomMode)
Parameters

zoomModeZoomMode

Sets the zoom mode to zoomMode. The default zoom mode is FitInView .

PySide6.QtPrintSupport.QPrintPreviewWidget.updatePreview()

This function updates the preview, which causes the paintRequested() signal to be emitted.

PySide6.QtPrintSupport.QPrintPreviewWidget.viewMode()
Return type

ViewMode

Returns the current view mode. The default view mode is SinglePageView .

See also

setViewMode()

PySide6.QtPrintSupport.QPrintPreviewWidget.zoomFactor()
Return type

float

Returns the zoom factor of the view.

See also

setZoomFactor()

PySide6.QtPrintSupport.QPrintPreviewWidget.zoomIn([zoom=1.1])
Parameters

zoom – float

Zooms the current view in by factor. The default value for factor is 1.1, which means the view will be scaled up by 10%.

PySide6.QtPrintSupport.QPrintPreviewWidget.zoomMode()
Return type

ZoomMode

Returns the current zoom mode.

PySide6.QtPrintSupport.QPrintPreviewWidget.zoomOut([zoom=1.1])
Parameters

zoom – float

Zooms the current view out by factor. The default value for factor is 1.1, which means the view will be scaled down by 10%.