|  | Home · All Classes · Modules

# QPrintPreviewWidget Class Reference
[QtGui module]

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

Inherits QWidget.

### Types

- enum ViewMode { SinglePageView, FacingPagesView, AllPagesView }
- enum ZoomMode { CustomZoom, FitToWidth, FitInView }

### Methods

- __init__ (self, QPrinter printer, QWidget parent = None, Qt.WindowFlags flags = 0)
- __init__ (self, QWidget parent = None, Qt.WindowFlags flags = 0)
- int currentPage (self)
- fitInView (self)
- fitToWidth (self)
- int numPages (self)
- QPrinter.Orientation orientation (self)
- print (self)
- print_ (self)
- setAllPagesViewMode (self)
- setCurrentPage (self, int pageNumber)
- setFacingPagesViewMode (self)
- setLandscapeOrientation (self)
- setOrientation (self, QPrinter.Orientation orientation)
- setPortraitOrientation (self)
- setSinglePageViewMode (self)
- setViewMode (self, ViewMode viewMode)
- setVisible (self, bool visible)
- setZoomFactor (self, float zoomFactor)
- setZoomMode (self, ZoomMode zoomMode)
- updatePreview (self)
- ViewMode viewMode (self)
- float zoomFactor (self)
- zoomIn (self, float zoom = 1.1)
- ZoomMode zoomMode (self)
- zoomOut (self, float zoom = 1.1)

### Qt Signals

- void paintRequested (QPrinter *)
- void previewChanged ()

## Detailed Description

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

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 exisiting 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 QPrinter.newPage(), to start a new page in the preview.

See also QPrinter, QPrintDialog, QPageSetupDialog, and QPrintPreviewDialog.

## Type Documentation

### QPrintPreviewWidget.ViewMode

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

Constant | Value | Description
--- | --- | ---
`QPrintPreviewWidget.SinglePageView` | `0` | A mode where single pages in the preview is viewed.
`QPrintPreviewWidget.FacingPagesView` | `1` | A mode where the facing pages in the preview is viewed.
`QPrintPreviewWidget.AllPagesView` | `2` | A view mode where all the pages in the preview is viewed.

### QPrintPreviewWidget.ZoomMode

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

Constant | Value | Description
--- | --- | ---
`QPrintPreviewWidget.CustomZoom` | `0` | The zoom is set to a custom zoom value.
`QPrintPreviewWidget.FitToWidth` | `1` | This mode fits the current page to the width of the view.
`QPrintPreviewWidget.FitInView` | `2` | This mode fits the current page inside the view.

## Method Documentation

### QPrintPreviewWidget.__init__ (self, QPrinter printer, QWidget parent = None, Qt.WindowFlags flags = 0)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

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 QWidget.setWindowFlags().

### QPrintPreviewWidget.__init__ (self, QWidget parent = None, Qt.WindowFlags flags = 0)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

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.

### int QPrintPreviewWidget.currentPage (self)

Returns the currently viewed page in the preview.

See also setCurrentPage().

### QPrintPreviewWidget.fitInView (self)

This method is also a Qt slot with the C++ signature `void fitInView()`.

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

### QPrintPreviewWidget.fitToWidth (self)

This method is also a Qt slot with the C++ signature `void fitToWidth()`.

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

### int QPrintPreviewWidget.numPages (self)

Returns the number of pages in the preview.

### QPrinter.Orientation QPrintPreviewWidget.orientation (self)

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

See also setOrientation().

### QPrintPreviewWidget.print (self)

This method is also a Qt slot with the C++ signature `void print()`.

Prints the preview to the printer associated with the preview.

### QPrintPreviewWidget.print_ (self)

This method is also a Qt slot with the C++ signature `void print()`.

Prints the preview to the printer associated with the preview.

### QPrintPreviewWidget.setAllPagesViewMode (self)

This method is also a Qt slot with the C++ signature `void setAllPagesViewMode()`.

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

### QPrintPreviewWidget.setCurrentPage (self, int pageNumber)

This method is also a Qt slot with the C++ signature `void setCurrentPage(int)`.

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

See also currentPage().

### QPrintPreviewWidget.setFacingPagesViewMode (self)

This method is also a Qt slot with the C++ signature `void setFacingPagesViewMode()`.

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

### QPrintPreviewWidget.setLandscapeOrientation (self)

This method is also a Qt slot with the C++ signature `void setLandscapeOrientation()`.

This is a convenience function and is the same as calling `setOrientation(QPrinter.Landscape)`.

### QPrintPreviewWidget.setOrientation (self, QPrinter.Orientation orientation)

This method is also a Qt slot with the C++ signature `void setOrientation(QPrinter::Orientation)`.

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

See also orientation().

### QPrintPreviewWidget.setPortraitOrientation (self)

This method is also a Qt slot with the C++ signature `void setPortraitOrientation()`.

This is a convenience function and is the same as calling `setOrientation(QPrinter.Portrait)`.

### QPrintPreviewWidget.setSinglePageViewMode (self)

This method is also a Qt slot with the C++ signature `void setSinglePageViewMode()`.

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

### QPrintPreviewWidget.setViewMode (self, ViewMode viewMode)

This method is also a Qt slot with the C++ signature `void setViewMode(QPrintPreviewWidget::ViewMode)`.

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

See also viewMode().

### QPrintPreviewWidget.setVisible (self, bool visible)

This method is also a Qt slot with the C++ signature `void setVisible(bool)`.

### QPrintPreviewWidget.setZoomFactor (self, float zoomFactor)

This method is also a Qt slot with the C++ signature `void setZoomFactor(qreal)`.

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().

### QPrintPreviewWidget.setZoomMode (self, ZoomMode zoomMode)

This method is also a Qt slot with the C++ signature `void setZoomMode(QPrintPreviewWidget::ZoomMode)`.

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

See also zoomMode(), viewMode(), and setViewMode().

### QPrintPreviewWidget.updatePreview (self)

This method is also a Qt slot with the C++ signature `void updatePreview()`.

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

### ViewMode QPrintPreviewWidget.viewMode (self)

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

See also setViewMode().

### float QPrintPreviewWidget.zoomFactor (self)

Returns the zoom factor of the view.

See also setZoomFactor().

### QPrintPreviewWidget.zoomIn (self, float zoom = 1.1)

This method is also a Qt slot with the C++ signature `void zoomIn(qreal = 1.1)`.

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%.

### ZoomMode QPrintPreviewWidget.zoomMode (self)

Returns the current zoom mode.

See also setZoomMode(), viewMode(), and setViewMode().

### QPrintPreviewWidget.zoomOut (self, float zoom = 1.1)

This method is also a Qt slot with the C++ signature `void zoomOut(qreal = 1.1)`.

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%.

## Qt Signal Documentation

### void paintRequested (QPrinter *)

This is the default overload of this signal.

This signal is emitted when the preview widget needs to generate a set of preview pages. printer is the printer associated with this preview widget.

### void previewChanged ()

This is the default overload of this signal.

This signal is emitted whenever the preview widget has changed some internal state, such as the orientation.