QPrintPreviewWidget 类

QPrintPreviewWidget 类提供为打印机输出而预览页面布局的 Widget。 更多...

头: #include <QPrintPreviewWidget>
CMake: find_package(Qt6 COMPONENTS PrintSupport REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::PrintSupport)
qmake: QT += printsupport
继承: QWidget

公共类型

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

公共函数

  QPrintPreviewWidget (QWidget * parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
  QPrintPreviewWidget (QPrinter * printer , QWidget * parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
virtual ~QPrintPreviewWidget ()
int currentPage () const
QPageLayout::Orientation orientation () const
int pageCount () const
QPrintPreviewWidget::ViewMode viewMode () const
qreal zoomFactor () const
QPrintPreviewWidget::ZoomMode zoomMode () const

重实现公共函数

virtual void setVisible (bool visible ) override

公共槽

void fitInView ()
void fitToWidth ()
void print ()
void setAllPagesViewMode ()
void setCurrentPage (int page )
void setFacingPagesViewMode ()
void setLandscapeOrientation ()
void setOrientation (QPageLayout::Orientation orientation )
void setPortraitOrientation ()
void setSinglePageViewMode ()
void setViewMode (QPrintPreviewWidget::ViewMode mode )
void setZoomFactor (qreal factor )
void setZoomMode (QPrintPreviewWidget::ZoomMode zoomMode )
void updatePreview ()
void zoomIn (qreal factor = 1.1)
void zoomOut (qreal factor = 1.1)

信号

void paintRequested (QPrinter * printer )
void previewChanged ()

详细描述

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

另请参阅 QPrinter , QPrintDialog , QPageSetupDialog ,和 QPrintPreviewDialog .

成员类型文档编制

enum QPrintPreviewWidget:: ViewMode

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

常量 描述
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.

enum QPrintPreviewWidget:: ZoomMode

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

常量 描述
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.

成员函数文档编制

QPrintPreviewWidget:: QPrintPreviewWidget ( QWidget * parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())

这是重载函数。

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

QPrintPreviewWidget:: QPrintPreviewWidget ( QPrinter * printer , QWidget * parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())

Constructs a QPrintPreviewWidget based on printer 和采用 parent as the parent widget. The widget flags flags 被传递给 QWidget 构造函数。

另请参阅 QWidget::setWindowFlags ().

[slot] void QPrintPreviewWidget:: fitInView ()

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

[slot] void QPrintPreviewWidget:: fitToWidth ()

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

[signal] void QPrintPreviewWidget:: paintRequested ( QPrinter * printer )

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.

[signal] void QPrintPreviewWidget:: previewChanged ()

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

[slot] void QPrintPreviewWidget:: print ()

Prints the preview to the printer associated with the preview.

[slot] void QPrintPreviewWidget:: setAllPagesViewMode ()

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

[slot] void QPrintPreviewWidget:: setCurrentPage ( int page )

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

另请参阅 currentPage ().

[slot] void QPrintPreviewWidget:: setFacingPagesViewMode ()

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

[slot] void QPrintPreviewWidget:: setLandscapeOrientation ()

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

[slot] void QPrintPreviewWidget:: setOrientation ( QPageLayout::Orientation orientation )

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

另请参阅 orientation ().

[slot] void QPrintPreviewWidget:: setPortraitOrientation ()

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

[slot] void QPrintPreviewWidget:: setSinglePageViewMode ()

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

[slot] void QPrintPreviewWidget:: setViewMode ( QPrintPreviewWidget::ViewMode mode )

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

另请参阅 viewMode ().

[slot] void QPrintPreviewWidget:: setZoomFactor ( qreal factor )

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.

另请参阅 zoomFactor ().

[slot] void QPrintPreviewWidget:: setZoomMode ( QPrintPreviewWidget::ZoomMode zoomMode )

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

另请参阅 zoomMode (), viewMode (),和 setViewMode ().

[slot] void QPrintPreviewWidget:: updatePreview ()

This function updates the preview, which causes the paintRequested () 信号被发射。

[slot] void QPrintPreviewWidget:: zoomIn ( qreal factor = 1.1)

Zooms the current view in by factor 。默认值对于 factor is 1.1, which means the view will be scaled up by 10%.

[slot] void QPrintPreviewWidget:: zoomOut ( qreal factor = 1.1)

Zooms the current view out by factor 。默认值对于 factor is 1.1, which means the view will be scaled down by 10%.

[虚拟] QPrintPreviewWidget:: ~QPrintPreviewWidget ()

销毁 QPrintPreviewWidget .

int QPrintPreviewWidget:: currentPage () const

Returns the currently viewed page in the preview.

另请参阅 setCurrentPage ().

QPageLayout::Orientation QPrintPreviewWidget:: orientation () const

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

另请参阅 setOrientation ().

int QPrintPreviewWidget:: pageCount () const

Returns the number of pages in the preview.

[override virtual] void QPrintPreviewWidget:: setVisible ( bool visible )

QPrintPreviewWidget::ViewMode QPrintPreviewWidget:: viewMode () const

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

另请参阅 setViewMode ().

qreal QPrintPreviewWidget:: zoomFactor () const

Returns the zoom factor of the view.

另请参阅 setZoomFactor ().

QPrintPreviewWidget::ZoomMode QPrintPreviewWidget:: zoomMode () const

Returns the current zoom mode.

另请参阅 setZoomMode (), viewMode (),和 setViewMode ().