Qt 4.8
Public Types | Public Functions | Protected Functions | Private Functions | Properties | Friends | List of all members
QPrinter Class Reference

The QPrinter class is a paint device that paints on a printer. More...

#include <qprinter.h>

Inheritance diagram for QPrinter:
QPaintDevice

Public Types

enum  ColorMode { GrayScale, Color }
 This enum type is used to indicate whether QPrinter should print in color or not. More...
 
enum  DuplexMode { DuplexNone = 0, DuplexAuto, DuplexLongSide, DuplexShortSide }
 This enum is used to indicate whether printing will occur on one or both sides of each sheet of paper (simplex or duplex printing). More...
 
enum  Orientation { Portrait, Landscape }
 This enum type (not to be confused with Orientation) is used to specify each page's orientation. More...
 
enum  OutputFormat { NativeFormat, PdfFormat, PostScriptFormat }
 The OutputFormat enum is used to describe the format QPrinter should use for printing. More...
 
enum  PageOrder { FirstPageFirst, LastPageFirst }
 This enum type is used by QPrinter to tell the application program how to print. More...
 
enum  PageSize {
  A4, B5, Letter, Legal,
  Executive, A0, A1, A2,
  A3, A5, A6, A7,
  A8, A9, B0, B1,
  B10, B2, B3, B4,
  B6, B7, B8, B9,
  C5E, Comm10E, DLE, Folio,
  Ledger, Tabloid, Custom, NPageSize = Custom
}
 Use QPrinter::PaperSize instead. More...
 
enum  PaperSize {
  A4, B5, Letter, Legal,
  Executive, A0, A1, A2,
  A3, A5, A6, A7,
  A8, A9, B0, B1,
  B10, B2, B3, B4,
  B6, B7, B8, B9,
  C5E, Comm10E, DLE, Folio,
  Ledger, Tabloid, Custom, NPageSize = Custom,
  NPaperSize = Custom
}
 This enum type specifies what paper size QPrinter should use. More...
 
enum  PaperSource {
  OnlyOne, Lower, Middle, Manual,
  Envelope, EnvelopeManual, Auto, Tractor,
  SmallFormat, LargeFormat, LargeCapacity, Cassette,
  FormSource, MaxPageSource
}
 This enum type specifies what paper source QPrinter is to use. More...
 
enum  PrinterMode { ScreenResolution, PrinterResolution, HighResolution }
 This enum describes the mode the printer should work in. More...
 
enum  PrinterState { Idle, Active, Aborted, Error }
 
enum  PrintRange { AllPages, Selection, PageRange, CurrentPage }
 Used to specify the print range selection option. More...
 
enum  Unit {
  Millimeter, Point, Inch, Pica,
  Didot, Cicero, DevicePixel
}
 This enum type is used to specify the measurement unit for page and paper sizes. More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 

Public Functions

bool abort ()
 Aborts the current print run. More...
 
int actualNumCopies () const
 Returns the number of copies that will be printed. More...
 
bool collateCopies () const
 Returns true if collation is turned on when multiple copies is selected. More...
 
ColorMode colorMode () const
 Returns the current color mode. More...
 
int copyCount () const
 Returns the number of copies that will be printed. More...
 
QString creator () const
 Returns the name of the application that created the document. More...
 
int devType () const
 
QString docName () const
 Returns the document name. More...
 
bool doubleSidedPrinting () const
 Returns true if double side printing is enabled. More...
 
DuplexMode duplex () const
 Returns the current duplex mode. More...
 
bool fontEmbeddingEnabled () const
 Returns true if font embedding is enabled. More...
 
int fromPage () const
 Returns the number of the first page in a range of pages to be printed (the "from page" setting). More...
 
bool fullPage () const
 Returns true if the origin of the printer's coordinate system is at the corner of the page and false if it is at the edge of the printable area. More...
 
HDC getDC () const
 
void getPageMargins (qreal *left, qreal *top, qreal *right, qreal *bottom, Unit unit) const
 Returns the page margins for this printer in left, top, right, bottom. More...
 
bool isValid () const
 Returns true if the printer currently selected is a valid printer in the system, or a pure PDF/PostScript printer; otherwise returns false. More...
 
bool newPage ()
 Tells the printer to eject the current page and to continue printing on a new page. More...
 
int numCopies () const
 Returns the number of copies to be printed. More...
 
Orientation orientation () const
 Returns the orientation setting. More...
 
QString outputFileName () const
 Returns the name of the output file. More...
 
OutputFormat outputFormat () const
 Returns the output format for this printer. More...
 
PageOrder pageOrder () const
 Returns the current page order. More...
 
QRect pageRect () const
 Returns the page's rectangle; this is usually smaller than the paperRect() since the page normally has margins between its borders and the paper. More...
 
QRectF pageRect (Unit) const
 Returns the page's rectangle in unit; this is usually smaller than the paperRect() since the page normally has margins between its borders and the paper. More...
 
PageSize pageSize () const
 Returns the printer page size. More...
 
QPaintEnginepaintEngine () const
 Returns the paint engine used by the printer. More...
 
QRect paperRect () const
 Returns the paper's rectangle; this is usually larger than the pageRect(). More...
 
QRectF paperRect (Unit) const
 Returns the paper's rectangle in unit; this is usually larger than the pageRect(). More...
 
PaperSize paperSize () const
 Returns the printer paper size. More...
 
QSizeF paperSize (Unit unit) const
 Returns the paper size in unit. More...
 
PaperSource paperSource () const
 Returns the printer's paper source. More...
 
QPrintEngineprintEngine () const
 Returns the print engine used by the printer. More...
 
QString printerName () const
 Returns the printer name. More...
 
QString printerSelectionOption () const
 Returns the printer options selection string. More...
 
PrinterState printerState () const
 Returns the current state of the printer. More...
 
QString printProgram () const
 Returns the name of the program that sends the print output to the printer. More...
 
PrintRange printRange () const
 Returns the page range of the QPrinter. More...
 
 QPrinter (PrinterMode mode=ScreenResolution)
 Creates a new printer object with the given mode. More...
 
 QPrinter (const QPrinterInfo &printer, PrinterMode mode=ScreenResolution)
 Creates a new printer object with the given printer and mode. More...
 
void releaseDC (HDC hdc) const
 
int resolution () const
 Returns the current assumed resolution of the printer, as set by setResolution() or by the printer driver. More...
 
void setCollateCopies (bool collate)
 Sets the default value for collation checkbox when the print dialog appears. More...
 
void setColorMode (ColorMode)
 Sets the printer's color mode to newColorMode, which can be either Color or GrayScale. More...
 
void setCopyCount (int)
 Sets the number of copies to be printed to count. More...
 
void setCreator (const QString &)
 Sets the name of the application that created the document to creator. More...
 
void setDocName (const QString &)
 Sets the document name to name. More...
 
void setDoubleSidedPrinting (bool enable)
 Enables double sided printing if doubleSided is true; otherwise disables it. More...
 
void setDuplex (DuplexMode duplex)
 Enables double sided printing based on the duplex mode. More...
 
void setFontEmbeddingEnabled (bool enable)
 Enabled or disables font embedding depending on enable. More...
 
void setFromTo (int fromPage, int toPage)
 Sets the range of pages to be printed to cover the pages with numbers specified by from and to, where from corresponds to the first page in the range and to corresponds to the last. More...
 
void setFullPage (bool)
 If fp is true, enables support for painting over the entire page; otherwise restricts painting to the printable area reported by the device. More...
 
void setNumCopies (int)
 Sets the number of copies to be printed to numCopies. More...
 
void setOrientation (Orientation)
 Sets the print orientation to orientation. More...
 
void setOutputFileName (const QString &)
 Sets the name of the output file to fileName. More...
 
void setOutputFormat (OutputFormat format)
 Sets the output format for this printer to format. More...
 
void setPageMargins (qreal left, qreal top, qreal right, qreal bottom, Unit unit)
 This function sets the left, top, right and bottom page margins for this printer. More...
 
void setPageOrder (PageOrder)
 Sets the page order to pageOrder. More...
 
void setPageSize (PageSize)
 Sets the printer page size based on newPageSize. More...
 
void setPaperSize (PaperSize)
 Sets the printer paper size to newPaperSize if that size is supported. More...
 
void setPaperSize (const QSizeF &paperSize, Unit unit)
 Sets the paper size based on paperSize in unit. More...
 
void setPaperSource (PaperSource)
 Sets the paper source setting to source. More...
 
void setPrinterName (const QString &)
 Sets the printer name to name. More...
 
void setPrinterSelectionOption (const QString &)
 Sets the printer to use option to select the printer. More...
 
void setPrintProgram (const QString &)
 Sets the name of the program that should do the print job to printProg. More...
 
void setPrintRange (PrintRange range)
 Sets the print range option in to be range. More...
 
void setResolution (int)
 Requests that the printer prints at dpi or as near to dpi as possible. More...
 
void setWinPageSize (int winPageSize)
 Sets the page size to be used by the printer under Windows to pageSize. More...
 
QList< PaperSourcesupportedPaperSources () const
 Returns the supported paper sizes for this printer. More...
 
QList< int > supportedResolutions () const
 Returns a list of the resolutions (a list of dots-per-inch integers) that the printer says it supports. More...
 
bool supportsMultipleCopies () const
 Returns true if the printer supports printing multiple copies of the same document in one job; otherwise false is returned. More...
 
int toPage () const
 Returns the number of the last page in a range of pages to be printed (the "to page" setting). More...
 
int winPageSize () const
 Returns the page size used by the printer under Windows. More...
 
 ~QPrinter ()
 Destroys the printer object and frees any allocated resources. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Protected Functions

int metric (PaintDeviceMetric) const
 Returns the metric for the given id. More...
 
void setEngines (QPrintEngine *printEngine, QPaintEngine *paintEngine)
 This function is used by subclasses of QPrinter to specify custom print and paint engines (printEngine and paintEngine, respectively). More...
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Private Functions

void init (PrinterMode mode)
 

Properties

QScopedPointer< QPrinterPrivated_ptr
 

Friends

class QAbstractPrintDialog
 
class QAbstractPrintDialogPrivate
 
class QPageSetupWidget
 
class QPrintDialogPrivate
 
class QPrintPreviewWidgetPrivate
 
class QTextDocument
 

Additional Inherited Members

- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 
- Protected Variables inherited from QPaintDevice
ushort painters
 

Detailed Description

The QPrinter class is a paint device that paints on a printer.

Note
This class or function is reentrant.

This device represents a series of pages of printed output, and is used in almost exactly the same way as other paint devices such as QWidget and QPixmap. A set of additional functions are provided to manage device-specific features, such as orientation and resolution, and to step through the pages in a document as it is generated.

When printing directly to a printer on Windows or Mac OS X, QPrinter uses the built-in printer drivers. On X11, QPrinter uses the Common Unix Printing System (CUPS) or the standard Unix lpr utility to send PostScript or PDF output to the printer. As an alternative, the printProgram() function can be used to specify the command or utility to use instead of the system default.

Note that setting parameters like paper size and resolution on an invalid printer is undefined. You can use QPrinter::isValid() to verify this before changing any parameters.

QPrinter supports a number of parameters, most of which can be changed by the end user through a print dialog. In general, QPrinter passes these functions onto the underlying QPrintEngine.

The most important parameters are:

Many of these functions can only be called before the actual printing begins (i.e., before QPainter::begin() is called). This usually makes sense because, for example, it's not possible to change the number of copies when you are halfway through printing. There are also some settings that the user sets (through the printer dialog) and that applications are expected to obey. See QAbstractPrintDialog's documentation for more details.

When QPainter::begin() is called, the QPrinter it operates on is prepared for a new page, enabling the QPainter to be used immediately to paint the first page in a document. Once the first page has been painted, newPage() can be called to request a new blank page to paint on, or QPainter::end() can be called to finish printing. The second page and all following pages are prepared using a call to newPage() before they are painted.

The first page in a document does not need to be preceded by a call to newPage(). You only need to calling newPage() after QPainter::begin() if you need to insert a blank page at the beginning of a printed document. Similarly, calling newPage() after the last page in a document is painted will result in a trailing blank page appended to the end of the printed document.

If you want to abort the print job, abort() will try its best to stop printing. It may cancel the entire job or just part of it.

Since QPrinter can print to any QPrintEngine subclass, it is possible to extend printing support to cover new types of printing subsystem by subclassing QPrintEngine and reimplementing its interface.

See also
QPrintDialog, {Printing with Qt}

Definition at line 66 of file qprinter.h.

Enumerations

◆ ColorMode

This enum type is used to indicate whether QPrinter should print in color or not.

  • Color print in color if available, otherwise in grayscale.
  • GrayScale print in grayscale, even on color printers.
Enumerator
GrayScale 
Color 

Definition at line 100 of file qprinter.h.

◆ DuplexMode

This enum is used to indicate whether printing will occur on one or both sides of each sheet of paper (simplex or duplex printing).

Since
4.4
  • DuplexNone Single sided (simplex) printing only.
  • DuplexAuto The printer's default setting is used to determine whether duplex printing is used.
  • DuplexLongSide Both sides of each sheet of paper are used for printing. The paper is turned over its longest edge before the second side is printed
  • DuplexShortSide Both sides of each sheet of paper are used for printing. The paper is turned over its shortest edge before the second side is printed
Enumerator
DuplexNone 
DuplexAuto 
DuplexLongSide 
DuplexShortSide 

Definition at line 139 of file qprinter.h.

◆ Orientation

This enum type (not to be confused with Orientation) is used to specify each page's orientation.

  • Portrait the page's height is greater than its width.
  • Landscape the page's width is greater than its height.

This type interacts with QPrinter::PaperSize and QPrinter::setFullPage() to determine the final size of the page available to the application.

Enumerator
Portrait 
Landscape 

Definition at line 78 of file qprinter.h.

◆ OutputFormat

The OutputFormat enum is used to describe the format QPrinter should use for printing.

  • NativeFormat QPrinter will print output using a method defined by the platform it is running on. This mode is the default when printing directly to a printer.
  • PdfFormat QPrinter will generate its output as a searchable PDF file. This mode is the default when printing to a file.
  • PostScriptFormat QPrinter will generate its output as in the PostScript format. (This feature was introduced in Qt 4.2.)
See also
outputFormat(), setOutputFormat(), setOutputFileName()
Enumerator
NativeFormat 
PdfFormat 
PostScriptFormat 

Definition at line 124 of file qprinter.h.

◆ PageOrder

This enum type is used by QPrinter to tell the application program how to print.

  • FirstPageFirst the lowest-numbered page should be printed first.
  • LastPageFirst the highest-numbered page should be printed first.
Enumerator
FirstPageFirst 
LastPageFirst 

Definition at line 97 of file qprinter.h.

◆ PageSize

Use QPrinter::PaperSize instead.

  • A0 841 x 1189 mm
  • A1 594 x 841 mm
  • A2 420 x 594 mm
  • A3 297 x 420 mm
  • A4 210 x 297 mm, 8.26 x 11.69 inches
  • A5 148 x 210 mm
  • A6 105 x 148 mm
  • A7 74 x 105 mm
  • A8 52 x 74 mm
  • A9 37 x 52 mm
  • B0 1030 x 1456 mm
  • B1 728 x 1030 mm
  • B10 32 x 45 mm
  • B2 515 x 728 mm
  • B3 364 x 515 mm
  • B4 257 x 364 mm
  • B5 182 x 257 mm, 7.17 x 10.13 inches
  • B6 128 x 182 mm
  • B7 91 x 128 mm
  • B8 64 x 91 mm
  • B9 45 x 64 mm
  • C5E 163 x 229 mm
  • Comm10E 105 x 241 mm, U.S. Common 10 Envelope
  • DLE 110 x 220 mm
  • Executive 7.5 x 10 inches, 191 x 254 mm
  • Folio 210 x 330 mm
  • Ledger 432 x 279 mm
  • Legal 8.5 x 14 inches, 216 x 356 mm
  • Letter 8.5 x 11 inches, 216 x 279 mm
  • Tabloid 279 x 432 mm
  • Custom Unknown, or a user defined size.
  • NPageSize
Enumerator
A4 
B5 
Letter 
Legal 
Executive 
A0 
A1 
A2 
A3 
A5 
A6 
A7 
A8 
A9 
B0 
B1 
B10 
B2 
B3 
B4 
B6 
B7 
B8 
B9 
C5E 
Comm10E 
DLE 
Folio 
Ledger 
Tabloid 
Custom 
NPageSize 

Definition at line 87 of file qprinter.h.

◆ PaperSize

This enum type specifies what paper size QPrinter should use.

Since
4.4

QPrinter does not check that the paper size is available; it just uses this information, together with QPrinter::Orientation and QPrinter::setFullPage(), to determine the printable area.

The defined sizes (with setFullPage(true)) are:

  • A0 841 x 1189 mm
  • A1 594 x 841 mm
  • A2 420 x 594 mm
  • A3 297 x 420 mm
  • A4 210 x 297 mm, 8.26 x 11.69 inches
  • A5 148 x 210 mm
  • A6 105 x 148 mm
  • A7 74 x 105 mm
  • A8 52 x 74 mm
  • A9 37 x 52 mm
  • B0 1000 x 1414 mm
  • B1 707 x 1000 mm
  • B2 500 x 707 mm
  • B3 353 x 500 mm
  • B4 250 x 353 mm
  • B5 176 x 250 mm, 6.93 x 9.84 inches
  • B6 125 x 176 mm
  • B7 88 x 125 mm
  • B8 62 x 88 mm
  • B9 33 x 62 mm
  • B10 31 x 44 mm
  • C5E 163 x 229 mm
  • Comm10E 105 x 241 mm, U.S. Common 10 Envelope
  • DLE 110 x 220 mm
  • Executive 7.5 x 10 inches, 190.5 x 254 mm
  • Folio 210 x 330 mm
  • Ledger 431.8 x 279.4 mm
  • Legal 8.5 x 14 inches, 215.9 x 355.6 mm
  • Letter 8.5 x 11 inches, 215.9 x 279.4 mm
  • Tabloid 279.4 x 431.8 mm
  • Custom Unknown, or a user defined size.

With setFullPage(false) (the default), the metrics will be a bit smaller; how much depends on the printer in use.

  • NPageSize
  • NPaperSize
Enumerator
A4 
B5 
Letter 
Legal 
Executive 
A0 
A1 
A2 
A3 
A5 
A6 
A7 
A8 
A9 
B0 
B1 
B10 
B2 
B3 
B4 
B6 
B7 
B8 
B9 
C5E 
Comm10E 
DLE 
Folio 
Ledger 
Tabloid 
Custom 
NPageSize 
NPaperSize 

Definition at line 91 of file qprinter.h.

91  { A4, B5, Letter, Legal, Executive,
92  A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
93  B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E,

◆ PaperSource

This enum type specifies what paper source QPrinter is to use.

QPrinter does not check that the paper source is available; it just uses this information to try and set the paper source. Whether it will set the paper source depends on whether the printer has that particular source.

Warning
This is currently only implemented for Windows.
  • Auto
  • Cassette
  • Envelope
  • EnvelopeManual
  • FormSource
  • LargeCapacity
  • LargeFormat
  • Lower
  • MaxPageSource
  • Middle
  • Manual
  • OnlyOne
  • Tractor
  • SmallFormat
Enumerator
OnlyOne 
Lower 
Middle 
Manual 
Envelope 
EnvelopeManual 
Auto 
Tractor 
SmallFormat 
LargeFormat 
LargeCapacity 
Cassette 
FormSource 
MaxPageSource 

Definition at line 103 of file qprinter.h.

◆ PrinterMode

This enum describes the mode the printer should work in.

It basically presets a certain resolution and working mode.

  • ScreenResolution Sets the resolution of the print device to the screen resolution. This has the big advantage that the results obtained when painting on the printer will match more or less exactly the visible output on the screen. It is the easiest to use, as font metrics on the screen and on the printer are the same. This is the default value. ScreenResolution will produce a lower quality output than HighResolution and should only be used for drafts.
  • PrinterResolution This value is deprecated. Is is equivalent to ScreenResolution on Unix and HighResolution on Windows and Mac. Due do the difference between ScreenResolution and HighResolution, use of this value may lead to non-portable printer code.
  • HighResolution On Windows, sets the printer resolution to that defined for the printer in use. For PostScript printing, sets the resolution of the PostScript driver to 1200 dpi.
Note
When rendering text on a QPrinter device, it is important to realize that the size of text, when specified in points, is independent of the resolution specified for the device itself. Therefore, it may be useful to specify the font size in pixels when combining text with graphics to ensure that their relative sizes are what you expect.
Enumerator
ScreenResolution 
PrinterResolution 
HighResolution 

Definition at line 70 of file qprinter.h.

◆ PrinterState

  • Idle
  • Active
  • Aborted
  • Error
Enumerator
Idle 
Active 
Aborted 
Error 

Definition at line 119 of file qprinter.h.

◆ PrintRange

Used to specify the print range selection option.

  • AllPages All pages should be printed.
  • Selection Only the selection should be printed.
  • PageRange The specified page range should be printed.
  • CurrentPage Only the current page should be printed.
See also
QAbstractPrintDialog::PrintRange
Enumerator
AllPages 
Selection 
PageRange 
CurrentPage 

Definition at line 127 of file qprinter.h.

◆ Unit

This enum type is used to specify the measurement unit for page and paper sizes.

Since
4.4
  • Millimeter
  • Point
  • Inch
  • Pica
  • Didot
  • Cicero
  • DevicePixel

Note the difference between Point and DevicePixel. The Point unit is defined to be 1/72th of an inch, while the DevicePixel unit is resolution dependant and is based on the actual pixels, or dots, on the printer.

Enumerator
Millimeter 
Point 
Inch 
Pica 
Didot 
Cicero 
DevicePixel 

Definition at line 129 of file qprinter.h.

Constructors and Destructors

◆ QPrinter() [1/2]

QPrinter::QPrinter ( PrinterMode  mode = ScreenResolution)
explicit

Creates a new printer object with the given mode.

Definition at line 632 of file qprinter.cpp.

633  : QPaintDevice(),
634  d_ptr(new QPrinterPrivate(this))
635 {
636  init(mode);
638  if (!defPrn.isNull()) {
639  setPrinterName(defPrn.printerName());
640  } else if (QPrinterInfo::availablePrinters().isEmpty()
644  }
645 }
QScopedPointer< QPrinterPrivate > d_ptr
Definition: qprinter.h:298
static QPrinterInfo defaultPrinter()
Returns the default printer on the system.
void init(PrinterMode mode)
Definition: qprinter.cpp:663
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
The QPrinterInfo class gives access to information about existing printers.
Definition: qprinterinfo.h:58
static QList< QPrinterInfo > availablePrinters()
Returns a list of available printers on the system.
QPaintEngine * paintEngine
Definition: qprinter_p.h:111
void setOutputFormat(OutputFormat format)
Sets the output format for this printer to format.
Definition: qprinter.cpp:765
void setPrinterName(const QString &)
Sets the printer name to name.
Definition: qprinter.cpp:845

◆ QPrinter() [2/2]

QPrinter::QPrinter ( const QPrinterInfo printer,
PrinterMode  mode = ScreenResolution 
)
explicit

Creates a new printer object with the given printer and mode.

Since
4.4

Definition at line 655 of file qprinter.cpp.

656  : QPaintDevice(),
657  d_ptr(new QPrinterPrivate(this))
658 {
659  init(mode);
660  setPrinterName(printer.printerName());
661 }
QScopedPointer< QPrinterPrivate > d_ptr
Definition: qprinter.h:298
void init(PrinterMode mode)
Definition: qprinter.cpp:663
QString printerName() const
Returns the name of the printer.
void setPrinterName(const QString &)
Sets the printer name to name.
Definition: qprinter.cpp:845

◆ ~QPrinter()

QPrinter::~QPrinter ( )

Destroys the printer object and frees any allocated resources.

If the printer is destroyed while a print job is in progress this may or may not affect the print job.

Definition at line 725 of file qprinter.cpp.

726 {
727  Q_D(QPrinter);
728  if (d->use_default_engine)
729  delete d->printEngine;
730 #ifndef QT_NO_PRINTPREVIEWWIDGET
731  delete d->previewEngine;
732 #endif
733 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

Functions

◆ abort()

bool QPrinter::abort ( )

Aborts the current print run.

Returns true if the print run was successfully aborted and printerState() will return QPrinter::Aborted; otherwise returns false.

It is not always possible to abort a print job. For example, all the data has gone to the printer but the printer cannot or will not cancel the job when asked to.

Definition at line 1979 of file qprinter.cpp.

1980 {
1981  Q_D(QPrinter);
1982  return d->printEngine->abort();
1983 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ actualNumCopies()

int QPrinter::actualNumCopies ( ) const

Returns the number of copies that will be printed.

Since
4.6

The default value is 1.

This function always returns the actual value specified in the print dialog or using setNumCopies().

Use copyCount() instead.

See also
setNumCopies(), numCopies()

Definition at line 1367 of file qprinter.cpp.

1368 {
1369  return copyCount();
1370 }
int copyCount() const
Returns the number of copies that will be printed.
Definition: qprinter.cpp:1430

◆ collateCopies()

bool QPrinter::collateCopies ( ) const

Returns true if collation is turned on when multiple copies is selected.

Since
4.1

Returns false if it is turned off when multiple copies is selected. When collating is turned off the printing of each individual page will be repeated the numCopies() amount before the next page is started. With collating turned on all pages are printed before the next copy of those pages is started.

See also
setCollateCopies()

Definition at line 1473 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::applyPrinterProperties().

1474 {
1475  Q_D(const QPrinter);
1476  return d->printEngine->property(QPrintEngine::PPK_CollateCopies).toBool();
1477 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ colorMode()

QPrinter::ColorMode QPrinter::colorMode ( ) const

Returns the current color mode.

See also
setColorMode()

Definition at line 1314 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::applyPrinterProperties(), and QPrintDialogPrivate::setPrinter().

1315 {
1316  Q_D(const QPrinter);
1317  return QPrinter::ColorMode(d->printEngine->property(QPrintEngine::PPK_ColorMode).toInt());
1318 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
ColorMode
This enum type is used to indicate whether QPrinter should print in color or not. ...
Definition: qprinter.h:100

◆ copyCount()

int QPrinter::copyCount ( ) const

Returns the number of copies that will be printed.

Since
4.7

The default value is 1.

See also
setCopyCount(), supportsMultipleCopies()

Definition at line 1430 of file qprinter.cpp.

Referenced by actualNumCopies(), QPrintDialogPrivate::applyPrinterProperties(), setOutputFormat(), and QPrintDialogPrivate::setPrinter().

1431 {
1432  Q_D(const QPrinter);
1433  return d->printEngine->property(QPrintEngine::PPK_CopyCount).toInt();
1434 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ creator()

QString QPrinter::creator ( ) const

Returns the name of the application that created the document.

See also
setCreator()

Definition at line 1066 of file qprinter.cpp.

1067 {
1068  Q_D(const QPrinter);
1069  return d->printEngine->property(QPrintEngine::PPK_Creator).toString();
1070 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ devType()

int QPrinter::devType ( ) const
virtual
Warning
This function is not part of the public interface.

Reimplemented from QPaintDevice.

Definition at line 823 of file qprinter.cpp.

824 {
825  return QInternal::Printer;
826 }

◆ docName()

QString QPrinter::docName ( ) const

Returns the document name.

See also
setDocName(), QPrintEngine::PrintEnginePropertyKey

Definition at line 1035 of file qprinter.cpp.

Referenced by QUnixPrintWidgetPrivate::applyPrinterProperties().

1036 {
1037  Q_D(const QPrinter);
1038  return d->printEngine->property(QPrintEngine::PPK_DocumentName).toString();
1039 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ doubleSidedPrinting()

bool QPrinter::doubleSidedPrinting ( ) const

Returns true if double side printing is enabled.

Since
4.2

Currently this option is only supported on X11.

Definition at line 1695 of file qprinter.cpp.

1696 {
1697  return duplex() != DuplexNone;
1698 }
DuplexMode duplex() const
Returns the current duplex mode.
Definition: qprinter.cpp:1727

◆ duplex()

QPrinter::DuplexMode QPrinter::duplex ( ) const

Returns the current duplex mode.

Since
4.4

Currently this option is only supported on X11.

Definition at line 1727 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::applyPrinterProperties(), and doubleSidedPrinting().

1728 {
1729  Q_D(const QPrinter);
1730  return static_cast <DuplexMode> (d->printEngine->property(QPrintEngine::PPK_Duplex).toInt());
1731 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
DuplexMode
This enum is used to indicate whether printing will occur on one or both sides of each sheet of paper...
Definition: qprinter.h:139
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ fontEmbeddingEnabled()

bool QPrinter::fontEmbeddingEnabled ( ) const

Returns true if font embedding is enabled.

Since
4.1

Currently this option is only supported on X11.

See also
setFontEmbeddingEnabled()

Definition at line 1642 of file qprinter.cpp.

1643 {
1644  Q_D(const QPrinter);
1645  return d->printEngine->property(QPrintEngine::PPK_FontEmbedding).toBool();
1646 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ fromPage()

int QPrinter::fromPage ( ) const

Returns the number of the first page in a range of pages to be printed (the "from page" setting).

Since
4.1

Pages in a document are numbered according to the convention that the first page is page 1.

By default, this function returns a special value of 0, meaning that the "from page" setting is unset.

Note
If fromPage() and toPage() both return 0, this indicates that the whole document will be printed.
See also
setFromTo(), toPage()

Definition at line 2168 of file qprinter.cpp.

2169 {
2170  Q_D(const QPrinter);
2171  return d->fromPage;
2172 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ fullPage()

bool QPrinter::fullPage ( ) const

Returns true if the origin of the printer's coordinate system is at the corner of the page and false if it is at the edge of the printable area.

See setFullPage() for details and caveats.

See also
setFullPage() PaperSize

Definition at line 1542 of file qprinter.cpp.

Referenced by QTextDocument::print().

1543 {
1544  Q_D(const QPrinter);
1545  return d->printEngine->property(QPrintEngine::PPK_FullPage).toBool();
1546 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ getDC()

HDC QPrinter::getDC ( ) const
virtual
Warning
This function is not part of the public interface.

Reimplemented from QPaintDevice.

Definition at line 2054 of file qprinter.cpp.

2055 {
2056  Q_D(const QPrinter);
2057  return d->printEngine->getPrinterDC();
2058 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ getPageMargins()

void QPrinter::getPageMargins ( qreal left,
qreal top,
qreal right,
qreal bottom,
QPrinter::Unit  unit 
) const

Returns the page margins for this printer in left, top, right, bottom.

Since
4.4

The unit of the returned margins are specified with the unit parameter.

Definition at line 1853 of file qprinter.cpp.

Referenced by QPageSetupWidget::selectPrinter(), and QPageSetupWidget::setPrinter().

1854 {
1855  Q_D(const QPrinter);
1856  Q_ASSERT(left && top && right && bottom);
1857  const qreal multiplier = qt_multiplierForUnit(unit, resolution());
1858  QList<QVariant> margins(d->printEngine->property(QPrintEngine::PPK_PageMargins).toList());
1859  *left = margins.at(0).toReal() / multiplier;
1860  *top = margins.at(1).toReal() / multiplier;
1861  *right = margins.at(2).toReal() / multiplier;
1862  *bottom = margins.at(3).toReal() / multiplier;
1863 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
double qt_multiplierForUnit(QPrinter::Unit unit, int resolution)
return the multiplier of converting from the unit value to postscript-points.
Definition: qprinter.cpp:123
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
int resolution() const
Returns the current assumed resolution of the printer, as set by setResolution() or by the printer dr...
Definition: qprinter.cpp:1578
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ init()

void QPrinter::init ( PrinterMode  mode)
private

Definition at line 663 of file qprinter.cpp.

Referenced by QPrinter().

664 {
665 #if !defined(Q_WS_X11)
666  if (!qApp) {
667 #else
668  if (!qApp || !X11) {
669 #endif
670  qFatal("QPrinter: Must construct a QApplication before a QPaintDevice");
671  return;
672  }
673  Q_D(QPrinter);
674 
675  d->printerMode = mode;
676  d->outputFormat = QPrinter::NativeFormat;
677  d->createDefaultEngines();
678 
679 #ifndef QT_NO_PRINTPREVIEWWIDGET
680  d->previewEngine = 0;
681 #endif
682  d->realPrintEngine = 0;
683  d->realPaintEngine = 0;
684 
685 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
686  if (QCUPSSupport::cupsVersion() >= 10200 && QCUPSSupport().currentPPD()) {
688  d->outputFormat = QPrinter::NativeFormat;
689  }
690 #endif
691 }
double d
Definition: qnumeric_p.h:62
#define X11
Definition: qt_x11_p.h:724
#define Q_D(Class)
Definition: qglobal.h:2482
#define qApp
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
Q_CORE_EXPORT void qFatal(const char *,...)
void setOutputFormat(OutputFormat format)
Sets the output format for this printer to format.
Definition: qprinter.cpp:765
static int cupsVersion()
Definition: qcups_p.h:75

◆ isValid()

bool QPrinter::isValid ( ) const

Returns true if the printer currently selected is a valid printer in the system, or a pure PDF/PostScript printer; otherwise returns false.

Since
4.4

To detect other failures check the output of QPainter::begin() or QPrinter::newPage().

QPrinter printer;
printer.setOutputFileName("/foobar/nonwritable.pdf");
QPainter painter;
if (! painter.begin(&printer)) { // failed to open file
qWarning("failed to open file, is it writable?");
return 1;
}
painter.drawText(10, 10, "Test");
if (! printer.newPage()) {
qWarning("failed in flushing page to disk, disk full?");
return 1;
}
painter.drawText(10, 10, "Test 2");
painter.end();
See also
setPrinterName()

Definition at line 895 of file qprinter.cpp.

Referenced by QTextControl::print(), and QTextDocument::print().

896 {
897  Q_D(const QPrinter);
898 #if defined(Q_WS_X11)
899  if (!qApp || !X11) {
900  return false;
901  }
902 #endif
903  return d->validPrinter;
904 }
double d
Definition: qnumeric_p.h:62
#define X11
Definition: qt_x11_p.h:724
#define Q_D(Class)
Definition: qglobal.h:2482
#define qApp
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ metric()

int QPrinter::metric ( PaintDeviceMetric  id) const
protectedvirtual

Returns the metric for the given id.

Warning
This function is not part of the public interface.

Reimplemented from QPaintDevice.

Definition at line 1873 of file qprinter.cpp.

1874 {
1875  Q_D(const QPrinter);
1876  return d->printEngine->metric(id);
1877 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ newPage()

bool QPrinter::newPage ( )

Tells the printer to eject the current page and to continue printing on a new page.

Returns true if this was successful; otherwise returns false.

Calling newPage() on an inactive QPrinter object will always fail.

Definition at line 1962 of file qprinter.cpp.

1963 {
1964  Q_D(QPrinter);
1965  if (d->printEngine->printerState() != QPrinter::Active)
1966  return false;
1967  return d->printEngine->newPage();
1968 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ numCopies()

int QPrinter::numCopies ( ) const

Returns the number of copies to be printed.

On Windows, Mac OS X and X11 systems that support CUPS, this will always return 1 as these operating systems can internally handle the number of copies.

On X11, this value will return the number of times the application is required to print in order to match the number specified in the printer setup dialog. This has been done since some printer drivers are not capable of buffering up the copies and in those cases the application must make an explicit call to the print code for each copy.

Use copyCount() in conjunction with supportsMultipleCopies() instead.

See also
setNumCopies(), actualNumCopies()

Definition at line 1343 of file qprinter.cpp.

1344 {
1345  Q_D(const QPrinter);
1346  return d->printEngine->property(QPrintEngine::PPK_NumberOfCopies).toInt();
1347 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ orientation()

QPrinter::Orientation QPrinter::orientation ( ) const

Returns the orientation setting.

This is driver-dependent, but is usually QPrinter::Portrait.

See also
setOrientation()

Definition at line 1098 of file qprinter.cpp.

Referenced by paperSize(), QPageSetupWidget::setPrinter(), and QPrintDialogPrivate::setPrinter().

1099 {
1100  Q_D(const QPrinter);
1101  return QPrinter::Orientation(d->printEngine->property(QPrintEngine::PPK_Orientation).toInt());
1102 }
double d
Definition: qnumeric_p.h:62
Orientation
This enum type (not to be confused with Orientation) is used to specify each page&#39;s orientation...
Definition: qprinter.h:78
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ outputFileName()

QString QPrinter::outputFileName ( ) const

Returns the name of the output file.

By default, this is an empty string (indicating that the printer shouldn't print to file).

See also
QPrintEngine::PrintEnginePropertyKey

Definition at line 950 of file qprinter.cpp.

Referenced by QUnixPrintWidgetPrivate::applyPrinterProperties(), printRange(), and QPrintDialogPrivate::setPrinter().

951 {
952  Q_D(const QPrinter);
953  return d->printEngine->property(QPrintEngine::PPK_OutputFileName).toString();
954 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ outputFormat()

QPrinter::OutputFormat QPrinter::outputFormat ( ) const

Returns the output format for this printer.

Since
4.1

Definition at line 813 of file qprinter.cpp.

Referenced by QUnixPrintWidgetPrivate::applyPrinterProperties(), QAbstractPageSetupDialogPrivate::setPrinter(), QPrintDialog::setVisible(), QUnixPrintWidgetPrivate::updateWidget(), and warnIfNotNative().

814 {
815  Q_D(const QPrinter);
816  return d->outputFormat;
817 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ pageOrder()

QPrinter::PageOrder QPrinter::pageOrder ( ) const

Returns the current page order.

The default page order is FirstPageFirst.

Definition at line 1286 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::applyPrinterProperties(), and QPrintDialogPrivate::setPrinter().

1287 {
1288  Q_D(const QPrinter);
1289  return QPrinter::PageOrder(d->printEngine->property(QPrintEngine::PPK_PageOrder).toInt());
1290 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
PageOrder
This enum type is used by QPrinter to tell the application program how to print.
Definition: qprinter.h:97

◆ pageRect() [1/2]

QRect QPrinter::pageRect ( ) const

Returns the page's rectangle; this is usually smaller than the paperRect() since the page normally has margins between its borders and the paper.

The unit of the returned rectangle is DevicePixel.

See also
paperSize()

Definition at line 1800 of file qprinter.cpp.

1801 {
1802  Q_D(const QPrinter);
1803  return d->printEngine->property(QPrintEngine::PPK_PageRect).toRect();
1804 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ pageRect() [2/2]

QRectF QPrinter::pageRect ( Unit  unit) const

Returns the page's rectangle in unit; this is usually smaller than the paperRect() since the page normally has margins between its borders and the paper.

Since
4.4
See also
paperSize()

Definition at line 1745 of file qprinter.cpp.

1746 {
1747  Q_D(const QPrinter);
1748  int res = resolution();
1749  const qreal multiplier = qt_multiplierForUnit(unit, res);
1750  // the page rect is in device pixels
1751  QRect devRect(d->printEngine->property(QPrintEngine::PPK_PageRect).toRect());
1752  if (unit == DevicePixel)
1753  return devRect;
1754  QRectF diRect(devRect.x()*72.0/res,
1755  devRect.y()*72.0/res,
1756  devRect.width()*72.0/res,
1757  devRect.height()*72.0/res);
1758  return QRectF(diRect.x()/multiplier, diRect.y()/multiplier,
1759  diRect.width()/multiplier, diRect.height()/multiplier);
1760 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
double qt_multiplierForUnit(QPrinter::Unit unit, int resolution)
return the multiplier of converting from the unit value to postscript-points.
Definition: qprinter.cpp:123
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
int resolution() const
Returns the current assumed resolution of the printer, as set by setResolution() or by the printer dr...
Definition: qprinter.cpp:1578
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ pageSize()

QPrinter::PageSize QPrinter::pageSize ( ) const

Returns the printer page size.

The default value is driver-dependent.

Use paperSize() instead.

Definition at line 1187 of file qprinter.cpp.

Referenced by QPageSetupWidget::_q_paperSizeChanged(), QPrintDialogPrivate::setPrinter(), and QPageSetupWidget::setupPrinter().

1188 {
1189  return paperSize();
1190 }
PaperSize paperSize() const
Returns the printer paper size.
Definition: qprinter.cpp:1140

◆ paintEngine()

QPaintEngine * QPrinter::paintEngine ( ) const
virtual

Returns the paint engine used by the printer.

Implements QPaintDevice.

Definition at line 1882 of file qprinter.cpp.

Referenced by QPrintDialog::QPrintDialog(), and setEngines().

1883 {
1884  Q_D(const QPrinter);
1885  return d->paintEngine;
1886 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ paperRect() [1/2]

QRect QPrinter::paperRect ( ) const

Returns the paper's rectangle; this is usually larger than the pageRect().

The unit of the returned rectangle is DevicePixel.

See also
pageRect()

Definition at line 1814 of file qprinter.cpp.

1815 {
1816  Q_D(const QPrinter);
1817  return d->printEngine->property(QPrintEngine::PPK_PaperRect).toRect();
1818 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ paperRect() [2/2]

QRectF QPrinter::paperRect ( Unit  unit) const

Returns the paper's rectangle in unit; this is usually larger than the pageRect().

Since
4.4
See also
pageRect()

Definition at line 1774 of file qprinter.cpp.

1775 {
1776  Q_D(const QPrinter);
1777  int res = resolution();
1778  const qreal multiplier = qt_multiplierForUnit(unit, resolution());
1779  // the page rect is in device pixels
1780  QRect devRect(d->printEngine->property(QPrintEngine::PPK_PaperRect).toRect());
1781  if (unit == DevicePixel)
1782  return devRect;
1783  QRectF diRect(devRect.x()*72.0/res,
1784  devRect.y()*72.0/res,
1785  devRect.width()*72.0/res,
1786  devRect.height()*72.0/res);
1787  return QRectF(diRect.x()/multiplier, diRect.y()/multiplier,
1788  diRect.width()/multiplier, diRect.height()/multiplier);
1789 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
double qt_multiplierForUnit(QPrinter::Unit unit, int resolution)
return the multiplier of converting from the unit value to postscript-points.
Definition: qprinter.cpp:123
#define Q_D(Class)
Definition: qglobal.h:2482
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
int resolution() const
Returns the current assumed resolution of the printer, as set by setResolution() or by the printer dr...
Definition: qprinter.cpp:1578
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ paperSize() [1/2]

QPrinter::PaperSize QPrinter::paperSize ( ) const

Returns the printer paper size.

Since
4.4 The default value is driver-dependent.
See also
setPaperSize() pageRect() paperRect()

Definition at line 1140 of file qprinter.cpp.

Referenced by pageSize(), paperSize(), QPageSetupWidget::selectPdfPsPrinter(), QPageSetupWidget::selectPrinter(), and QPageSetupWidget::setPrinter().

1141 {
1142  Q_D(const QPrinter);
1143  return QPrinter::PaperSize(d->printEngine->property(QPrintEngine::PPK_PaperSize).toInt());
1144 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
PaperSize
This enum type specifies what paper size QPrinter should use.
Definition: qprinter.h:91

◆ paperSize() [2/2]

QSizeF QPrinter::paperSize ( Unit  unit) const

Returns the paper size in unit.

Since
4.4
See also
setPaperSize()

Definition at line 1243 of file qprinter.cpp.

1244 {
1245  Q_D(const QPrinter);
1246  int res = resolution();
1247  const qreal multiplier = qt_multiplierForUnit(unit, res);
1248  PaperSize paperType = paperSize();
1249  if (paperType == Custom) {
1250  QSizeF size = d->printEngine->property(QPrintEngine::PPK_CustomPaperSize).toSizeF();
1251  return QSizeF(size.width() / multiplier, size.height() / multiplier);
1252  }
1253  else {
1254  return qt_printerPaperSize(orientation(), paperType, unit, res);
1255  }
1256 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
double qt_multiplierForUnit(QPrinter::Unit unit, int resolution)
return the multiplier of converting from the unit value to postscript-points.
Definition: qprinter.cpp:123
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
PaperSize paperSize() const
Returns the printer paper size.
Definition: qprinter.cpp:1140
Orientation orientation() const
Returns the orientation setting.
Definition: qprinter.cpp:1098
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
QSizeF qt_printerPaperSize(QPrinter::Orientation orientation, QPrinter::PaperSize paperSize, QPrinter::Unit unit, int resolution)
Definition: qprinter.cpp:145
PaperSize
This enum type specifies what paper size QPrinter should use.
Definition: qprinter.h:91
int resolution() const
Returns the current assumed resolution of the printer, as set by setResolution() or by the printer dr...
Definition: qprinter.cpp:1578

◆ paperSource()

QPrinter::PaperSource QPrinter::paperSource ( ) const

Returns the printer's paper source.

This is Manual or a printer tray or paper cassette.

Definition at line 1604 of file qprinter.cpp.

Referenced by QPageSetupWidget::setPrinter().

1605 {
1606  Q_D(const QPrinter);
1607  return QPrinter::PaperSource(d->printEngine->property(QPrintEngine::PPK_PaperSource).toInt());
1608 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
PaperSource
This enum type specifies what paper source QPrinter is to use.
Definition: qprinter.h:103

◆ printEngine()

QPrintEngine * QPrinter::printEngine ( ) const

Returns the print engine used by the printer.

Since
4.1

Definition at line 1896 of file qprinter.cpp.

Referenced by QUnixPrintWidgetPrivate::setCupsProperties(), setEngines(), and QPageSetupWidget::setupPrinter().

1897 {
1898  Q_D(const QPrinter);
1899  return d->printEngine;
1900 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ printerName()

QString QPrinter::printerName ( ) const

Returns the printer name.

This value is initially set to the name of the default printer.

See also
setPrinterName()

Definition at line 834 of file qprinter.cpp.

Referenced by QUnixPrintWidgetPrivate::applyPrinterProperties(), QPrinterInfo::QPrinterInfo(), setPrinterName(), and QUnixPrintWidgetPrivate::updateWidget().

835 {
836  Q_D(const QPrinter);
837  return d->printEngine->property(QPrintEngine::PPK_PrinterName).toString();
838 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ printerSelectionOption()

QString QPrinter::printerSelectionOption ( ) const

Returns the printer options selection string.

This is useful only if the print command has been explicitly set.

The default value (an empty string) implies that the printer should be selected in a system-dependent manner.

Any other value implies that the given value should be used.

Warning
This function is not available on Windows.
See also
setPrinterSelectionOption()

Referenced by supportedPaperSources().

◆ printerState()

QPrinter::PrinterState QPrinter::printerState ( ) const

Returns the current state of the printer.

This may not always be accurate (for example if the printer doesn't have the capability of reporting its state to the operating system).

Definition at line 1990 of file qprinter.cpp.

1991 {
1992  Q_D(const QPrinter);
1993  return d->printEngine->printerState();
1994 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ printProgram()

QString QPrinter::printProgram ( ) const

Returns the name of the program that sends the print output to the printer.

The default is to return an empty string; meaning that QPrinter will try to be smart in a system-dependent way. On X11 only, you can set it to something different to use a specific print program. On the other platforms, this returns an empty string.

See also
setPrintProgram(), setPrinterSelectionOption()

Definition at line 1005 of file qprinter.cpp.

1006 {
1007  Q_D(const QPrinter);
1008  return d->printEngine->property(QPrintEngine::PPK_PrinterProgram).toString();
1009 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ printRange()

QPrinter::PrintRange QPrinter::printRange ( ) const

Returns the page range of the QPrinter.

Since
4.1

After the print setup dialog has been opened, this function returns the value selected by the user.

See also
setPrintRange()

Definition at line 2265 of file qprinter.cpp.

Referenced by QTextControl::print().

2266 {
2267  Q_D(const QPrinter);
2268  return PrintRange(d->printRange);
2269 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
PrintRange
Used to specify the print range selection option.
Definition: qprinter.h:127

◆ releaseDC()

void QPrinter::releaseDC ( HDC  hdc) const
virtual
Warning
This function is not part of the public interface.

Reimplemented from QPaintDevice.

Definition at line 2063 of file qprinter.cpp.

2064 {
2065  Q_D(const QPrinter);
2066  d->printEngine->releasePrinterDC(hdc);
2067 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ resolution()

int QPrinter::resolution ( ) const

Returns the current assumed resolution of the printer, as set by setResolution() or by the printer driver.

See also
setResolution()

Definition at line 1578 of file qprinter.cpp.

Referenced by getPageMargins(), pageRect(), paperRect(), paperSize(), setPageMargins(), and setPaperSize().

1579 {
1580  Q_D(const QPrinter);
1581  return d->printEngine->property(QPrintEngine::PPK_Resolution).toInt();
1582 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ setCollateCopies()

void QPrinter::setCollateCopies ( bool  collate)

Sets the default value for collation checkbox when the print dialog appears.

Since
4.1

If collate is true, it will enable setCollateCopiesEnabled(). The default value is false. This value will be changed by what the user presses in the print dialog.

See also
collateCopies()

Definition at line 1493 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::setupPrinter().

1494 {
1495  Q_D(QPrinter);
1496  ABORT_IF_ACTIVE("QPrinter::setCollateCopies");
1497  d->printEngine->setProperty(QPrintEngine::PPK_CollateCopies, collate);
1498  d->addToManualSetList(QPrintEngine::PPK_CollateCopies);
1499 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ setColorMode()

void QPrinter::setColorMode ( ColorMode  newColorMode)

Sets the printer's color mode to newColorMode, which can be either Color or GrayScale.

See also
colorMode()

Definition at line 1300 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::_q_okClicked(), and QPrintDialogPrivate::setupPrinter().

1301 {
1302  Q_D(QPrinter);
1303  ABORT_IF_ACTIVE("QPrinter::setColorMode");
1304  d->printEngine->setProperty(QPrintEngine::PPK_ColorMode, newColorMode);
1305  d->addToManualSetList(QPrintEngine::PPK_ColorMode);
1306 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ setCopyCount()

void QPrinter::setCopyCount ( int  count)

Sets the number of copies to be printed to count.

Since
4.7

The printer driver reads this setting and prints the specified number of copies.

See also
copyCount(), supportsMultipleCopies()

Definition at line 1411 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::_q_okClicked(), and QPrintDialogPrivate::setupPrinter().

1412 {
1413  Q_D(QPrinter);
1414  ABORT_IF_ACTIVE("QPrinter::setCopyCount;");
1415  d->printEngine->setProperty(QPrintEngine::PPK_CopyCount, count);
1416  d->addToManualSetList(QPrintEngine::PPK_CopyCount);
1417 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ setCreator()

void QPrinter::setCreator ( const QString creator)

Sets the name of the application that created the document to creator.

This function is only applicable to the X11 version of Qt. If no creator name is specified, the creator will be set to "Qt" followed by some version number.

See also
creator()

Definition at line 1083 of file qprinter.cpp.

1084 {
1085  Q_D(QPrinter);
1086  ABORT_IF_ACTIVE("QPrinter::setCreator");
1087  d->printEngine->setProperty(QPrintEngine::PPK_Creator, creator);
1088  d->addToManualSetList(QPrintEngine::PPK_Creator);
1089 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ setDocName()

void QPrinter::setDocName ( const QString name)

Sets the document name to name.

On X11, the document name is for example used as the default output filename in QPrintDialog. Note that the document name does not affect the file name if the printer is printing to a file. Use the setOutputFile() function for this.

See also
docName(), QPrintEngine::PrintEnginePropertyKey

Definition at line 1052 of file qprinter.cpp.

Referenced by QTextDocument::print().

1053 {
1054  Q_D(QPrinter);
1055  ABORT_IF_ACTIVE("QPrinter::setDocName");
1056  d->printEngine->setProperty(QPrintEngine::PPK_DocumentName, name);
1057  d->addToManualSetList(QPrintEngine::PPK_DocumentName);
1058 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ setDoubleSidedPrinting()

void QPrinter::setDoubleSidedPrinting ( bool  doubleSided)

Enables double sided printing if doubleSided is true; otherwise disables it.

Since
4.2

Currently this option is only supported on X11.

Definition at line 1679 of file qprinter.cpp.

1680 {
1681  setDuplex(doubleSided ? DuplexAuto : DuplexNone);
1682 }
void setDuplex(DuplexMode duplex)
Enables double sided printing based on the duplex mode.
Definition: qprinter.cpp:1710

◆ setDuplex()

void QPrinter::setDuplex ( DuplexMode  duplex)

Enables double sided printing based on the duplex mode.

Since
4.4

Currently this option is only supported on X11.

Definition at line 1710 of file qprinter.cpp.

Referenced by setDoubleSidedPrinting(), and QPrintDialogPrivate::setupPrinter().

1711 {
1712  Q_D(QPrinter);
1713  d->printEngine->setProperty(QPrintEngine::PPK_Duplex, duplex);
1714  d->addToManualSetList(QPrintEngine::PPK_Duplex);
1715 }
DuplexMode duplex() const
Returns the current duplex mode.
Definition: qprinter.cpp:1727
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ setEngines()

void QPrinter::setEngines ( QPrintEngine printEngine,
QPaintEngine paintEngine 
)
protected

This function is used by subclasses of QPrinter to specify custom print and paint engines (printEngine and paintEngine, respectively).

QPrinter does not take ownership of the engines, so you need to manage these engine instances yourself.

Note that changing the engines will reset the printer state and all its properties.

See also
printEngine() paintEngine() setOutputFormat()
Since
4.1

Definition at line 708 of file qprinter.cpp.

709 {
710  Q_D(QPrinter);
711 
712  if (d->use_default_engine)
713  delete d->printEngine;
714 
715  d->printEngine = printEngine;
716  d->paintEngine = paintEngine;
717  d->use_default_engine = false;
718 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QPrintEngine * printEngine() const
Returns the print engine used by the printer.
Definition: qprinter.cpp:1896
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
QPaintEngine * paintEngine() const
Returns the paint engine used by the printer.
Definition: qprinter.cpp:1882

◆ setFontEmbeddingEnabled()

void QPrinter::setFontEmbeddingEnabled ( bool  enable)

Enabled or disables font embedding depending on enable.

Since
4.1

Currently this option is only supported on X11.

See also
fontEmbeddingEnabled()

Definition at line 1623 of file qprinter.cpp.

1624 {
1625  Q_D(QPrinter);
1626  d->printEngine->setProperty(QPrintEngine::PPK_FontEmbedding, enable);
1627  d->addToManualSetList(QPrintEngine::PPK_FontEmbedding);
1628 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ setFromTo()

void QPrinter::setFromTo ( int  from,
int  to 
)

Sets the range of pages to be printed to cover the pages with numbers specified by from and to, where from corresponds to the first page in the range and to corresponds to the last.

Since
4.1
Note
Pages in a document are numbered according to the convention that the first page is page 1. However, if from and to are both set to 0, the whole document will be printed.

This function is mostly used to set a default value that the user can override in the print dialog when you call setup().

See also
fromPage(), toPage()

Definition at line 2222 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::setupPrinter().

2223 {
2224  Q_D(QPrinter);
2225  if (from > to) {
2226  qWarning() << "QPrinter::setFromTo: 'from' must be less than or equal to 'to'";
2227  from = to;
2228  }
2229  d->fromPage = from;
2230  d->toPage = to;
2231 
2232  if (d->minPage == 0 && d->maxPage == 0) {
2233  d->minPage = 1;
2234  d->maxPage = to;
2236  }
2237 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setFullPage()

void QPrinter::setFullPage ( bool  fp)

If fp is true, enables support for painting over the entire page; otherwise restricts painting to the printable area reported by the device.

By default, full page printing is disabled. In this case, the origin of the QPrinter's coordinate system coincides with the top-left corner of the printable area.

If full page printing is enabled, the origin of the QPrinter's coordinate system coincides with the top-left corner of the paper itself. In this case, the device metrics will report the exact same dimensions as indicated by PaperSize. It may not be possible to print on the entire physical page because of the printer's margins, so the application must account for the margins itself.

See also
fullPage(), setPaperSize(), width(), height(), {Printing with Qt}

Definition at line 1524 of file qprinter.cpp.

1525 {
1526  Q_D(QPrinter);
1527  d->printEngine->setProperty(QPrintEngine::PPK_FullPage, fp);
1528  d->addToManualSetList(QPrintEngine::PPK_FullPage);
1529 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ setNumCopies()

void QPrinter::setNumCopies ( int  numCopies)

Sets the number of copies to be printed to numCopies.

The printer driver reads this setting and prints the specified number of copies.

Use setCopyCount() instead.

See also
numCopies()

Definition at line 1389 of file qprinter.cpp.

1390 {
1391  Q_D(QPrinter);
1392  ABORT_IF_ACTIVE("QPrinter::setNumCopies");
1393  d->printEngine->setProperty(QPrintEngine::PPK_NumberOfCopies, numCopies);
1394  d->addToManualSetList(QPrintEngine::PPK_NumberOfCopies);
1395 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
int numCopies() const
Returns the number of copies to be printed.
Definition: qprinter.cpp:1343
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ setOrientation()

void QPrinter::setOrientation ( Orientation  orientation)

Sets the print orientation to orientation.

The orientation can be either QPrinter::Portrait or QPrinter::Landscape.

The printer driver reads this setting and prints using the specified orientation.

On Windows, this option can be changed while printing and will take effect from the next call to newPage().

On Mac OS X, changing the orientation during a print job has no effect.

See also
orientation()

Definition at line 1122 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::_q_okClicked(), and QPageSetupWidget::setupPrinter().

1123 {
1124  Q_D(QPrinter);
1125  d->printEngine->setProperty(QPrintEngine::PPK_Orientation, orientation);
1126  d->addToManualSetList(QPrintEngine::PPK_Orientation);
1127 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Orientation orientation() const
Returns the orientation setting.
Definition: qprinter.cpp:1098
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ setOutputFileName()

void QPrinter::setOutputFileName ( const QString fileName)

Sets the name of the output file to fileName.

Setting a null or empty name (0 or "") disables printing to a file. Setting a non-empty name enables printing to a file.

This can change the value of outputFormat(). If the file name has the suffix ".ps" then PostScript is automatically selected as output format. If the file name has the ".pdf" suffix PDF is generated. If the file name has a suffix other than ".ps" and ".pdf", the output format used is the one set with setOutputFormat().

QPrinter uses Qt's cross-platform PostScript or PDF print engines respectively. If you can produce this format natively, for example Mac OS X can generate PDF's from its print engine, set the output format back to NativeFormat.

See also
outputFileName() setOutputToFile() setOutputFormat()

Definition at line 976 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::_q_okClicked(), printRange(), and QUnixPrintWidgetPrivate::setupPrinter().

977 {
978  Q_D(QPrinter);
979  ABORT_IF_ACTIVE("QPrinter::setOutputFileName");
980 
981  QFileInfo fi(fileName);
982  if (!fi.suffix().compare(QLatin1String("ps"), Qt::CaseInsensitive))
984  else if (!fi.suffix().compare(QLatin1String("pdf"), Qt::CaseInsensitive))
986  else if (fileName.isEmpty())
988 
989  d->printEngine->setProperty(QPrintEngine::PPK_OutputFileName, fileName);
990  d->addToManualSetList(QPrintEngine::PPK_OutputFileName);
991 }
double d
Definition: qnumeric_p.h:62
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
void setOutputFormat(OutputFormat format)
Sets the output format for this printer to format.
Definition: qprinter.cpp:765
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ setOutputFormat()

void QPrinter::setOutputFormat ( OutputFormat  format)

Sets the output format for this printer to format.

Since
4.1

Definition at line 765 of file qprinter.cpp.

Referenced by init(), QPrinter(), setOutputFileName(), setPrinterName(), and QUnixPrintWidgetPrivate::setupPrinter().

766 {
767 
768 #ifndef QT_NO_PDF
769  Q_D(QPrinter);
770  if (d->validPrinter && d->outputFormat == format)
771  return;
772  d->outputFormat = format;
773 
774  QPrintEngine *oldPrintEngine = d->printEngine;
775  const bool def_engine = d->use_default_engine;
776  d->printEngine = 0;
777 
778  d->createDefaultEngines();
779 
780  if (oldPrintEngine) {
781  for (int i = 0; i < d->manualSetList.size(); ++i) {
782  QPrintEngine::PrintEnginePropertyKey key = d->manualSetList[i];
783  QVariant prop;
784  // PPK_NumberOfCopies need special treatmeant since it in most cases
785  // will return 1, disregarding the actual value that was set
787  prop = QVariant(copyCount());
788  else
789  prop = oldPrintEngine->property(key);
790  if (prop.isValid())
791  d->printEngine->setProperty(key, prop);
792  }
793  }
794 
795  if (def_engine)
796  delete oldPrintEngine;
797 
798  if (d->outputFormat == QPrinter::PdfFormat || d->outputFormat == QPrinter::PostScriptFormat)
799  d->validPrinter = true;
800 #else
801  Q_UNUSED(format);
802 #endif
803 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
virtual QVariant property(PrintEnginePropertyKey key) const =0
Returns the print engine&#39;s property specified by key.
The QPrintEngine class defines an interface for how QPrinter interacts with a given printing subsyste...
Definition: qprintengine.h:56
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
int key
int copyCount() const
Returns the number of copies that will be printed.
Definition: qprinter.cpp:1430
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
PrintEnginePropertyKey
This enum is used to communicate properties between the print engine and QPrinter.
Definition: qprintengine.h:60

◆ setPageMargins()

void QPrinter::setPageMargins ( qreal  left,
qreal  top,
qreal  right,
qreal  bottom,
QPrinter::Unit  unit 
)

This function sets the left, top, right and bottom page margins for this printer.

Since
4.4

The unit of the margins are specified with the unit parameter.

Definition at line 1831 of file qprinter.cpp.

Referenced by QTextDocument::print(), and QPageSetupWidget::setupPrinter().

1832 {
1833  Q_D(QPrinter);
1834  const qreal multiplier = qt_multiplierForUnit(unit, resolution());
1835  QList<QVariant> margins;
1836  margins << (left * multiplier) << (top * multiplier)
1837  << (right * multiplier) << (bottom * multiplier);
1838  d->printEngine->setProperty(QPrintEngine::PPK_PageMargins, margins);
1839  d->addToManualSetList(QPrintEngine::PPK_PageMargins);
1840  d->hasCustomPageMargins = true;
1841 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
double qt_multiplierForUnit(QPrinter::Unit unit, int resolution)
return the multiplier of converting from the unit value to postscript-points.
Definition: qprinter.cpp:123
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
int resolution() const
Returns the current assumed resolution of the printer, as set by setResolution() or by the printer dr...
Definition: qprinter.cpp:1578
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ setPageOrder()

void QPrinter::setPageOrder ( PageOrder  pageOrder)

Sets the page order to pageOrder.

The page order can be QPrinter::FirstPageFirst or QPrinter::LastPageFirst. The application is responsible for reading the page order and printing accordingly.

This function is mostly useful for setting a default value that the user can override in the print dialog.

This function is only supported under X11.

Definition at line 1271 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::_q_okClicked().

1272 {
1273  Q_D(QPrinter);
1274  ABORT_IF_ACTIVE("QPrinter::setPageOrder");
1275  d->printEngine->setProperty(QPrintEngine::PPK_PageOrder, pageOrder);
1276  d->addToManualSetList(QPrintEngine::PPK_PageOrder);
1277 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
PageOrder pageOrder() const
Returns the current page order.
Definition: qprinter.cpp:1286
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ setPageSize()

void QPrinter::setPageSize ( PageSize  newPageSize)

Sets the printer page size based on newPageSize.

Use setPaperSize() instead.

Definition at line 1204 of file qprinter.cpp.

1205 {
1206  setPaperSize(newPageSize);
1207 }
void setPaperSize(PaperSize)
Sets the printer paper size to newPaperSize if that size is supported.
Definition: qprinter.cpp:1163

◆ setPaperSize() [1/2]

void QPrinter::setPaperSize ( PaperSize  newPaperSize)

Sets the printer paper size to newPaperSize if that size is supported.

Since
4.4

The result is undefined if newPaperSize is not supported.

The default paper size is driver-dependent.

This function is useful mostly for setting a default value that the user can override in the print dialog.

See also
paperSize() PaperSize setFullPage() setResolution() pageRect() paperRect()

Definition at line 1163 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::_q_okClicked(), QUnixPrintWidgetPrivate::setCupsProperties(), setPageSize(), and QPageSetupWidget::setupPrinter().

1164 {
1165  Q_D(QPrinter);
1166  if (d->paintEngine->type() != QPaintEngine::Pdf)
1167  ABORT_IF_ACTIVE("QPrinter::setPaperSize");
1168  if (newPaperSize < 0 || newPaperSize >= NPaperSize) {
1169  qWarning("QPrinter::setPaperSize: Illegal paper size %d", newPaperSize);
1170  return;
1171  }
1172  d->printEngine->setProperty(QPrintEngine::PPK_PaperSize, newPaperSize);
1173  d->addToManualSetList(QPrintEngine::PPK_PaperSize);
1174  d->hasUserSetPageSize = true;
1175 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
Q_CORE_EXPORT void qWarning(const char *,...)
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ setPaperSize() [2/2]

void QPrinter::setPaperSize ( const QSizeF paperSize,
QPrinter::Unit  unit 
)

Sets the paper size based on paperSize in unit.

Since
4.4
See also
paperSize()

Definition at line 1220 of file qprinter.cpp.

1221 {
1222  Q_D(QPrinter);
1223  if (d->paintEngine->type() != QPaintEngine::Pdf)
1224  ABORT_IF_ACTIVE("QPrinter::setPaperSize");
1225  const qreal multiplier = qt_multiplierForUnit(unit, resolution());
1226  QSizeF size(paperSize.width() * multiplier, paperSize.height() * multiplier);
1227  d->printEngine->setProperty(QPrintEngine::PPK_CustomPaperSize, size);
1228  d->addToManualSetList(QPrintEngine::PPK_CustomPaperSize);
1229  d->hasUserSetPageSize = true;
1230 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
double qt_multiplierForUnit(QPrinter::Unit unit, int resolution)
return the multiplier of converting from the unit value to postscript-points.
Definition: qprinter.cpp:123
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
int resolution() const
Returns the current assumed resolution of the printer, as set by setResolution() or by the printer dr...
Definition: qprinter.cpp:1578
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ setPaperSource()

void QPrinter::setPaperSource ( PaperSource  source)

Sets the paper source setting to source.

Windows only: This option can be changed while printing and will take effect from the next call to newPage()

See also
paperSource()

Definition at line 1593 of file qprinter.cpp.

Referenced by QPageSetupWidget::setupPrinter().

1594 {
1595  Q_D(QPrinter);
1596  d->printEngine->setProperty(QPrintEngine::PPK_PaperSource, source);
1597  d->addToManualSetList(QPrintEngine::PPK_PaperSource);
1598 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ setPrinterName()

void QPrinter::setPrinterName ( const QString name)

Sets the printer name to name.

See also
printerName(), isValid()

Definition at line 845 of file qprinter.cpp.

Referenced by QPrinter(), and QUnixPrintWidgetPrivate::setupPrinter().

846 {
847  Q_D(QPrinter);
848  ABORT_IF_ACTIVE("QPrinter::setPrinterName");
849 
850 #if defined(Q_OS_UNIX) && !defined(QT_NO_CUPS)
851  if(d->use_default_engine
852  && d->outputFormat == QPrinter::NativeFormat) {
853  if (QCUPSSupport::cupsVersion() >= 10200
856  else
858  d->outputFormat = QPrinter::NativeFormat;
859  }
860 #endif
861 
863  if (name.isEmpty()) {
864  d->validPrinter = d->outputFormat == QPrinter::PdfFormat || d->outputFormat == QPrinter::PostScriptFormat;
865  } else {
866  d->validPrinter = false;
867  for (int i = 0; i < prnList.size(); ++i) {
868  if (prnList[i].printerName() == name) {
869  d->validPrinter = true;
870  break;
871  }
872  }
873  }
874 
875  d->printEngine->setProperty(QPrintEngine::PPK_PrinterName, name);
876  d->addToManualSetList(QPrintEngine::PPK_PrinterName);
877 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QList< QPrinterInfo > availablePrinters()
Returns a list of available printers on the system.
void setOutputFormat(OutputFormat format)
Sets the output format for this printer to format.
Definition: qprinter.cpp:765
QString printerName() const
Returns the printer name.
Definition: qprinter.cpp:834
static bool printerHasPPD(const char *printerName)
Definition: qcups.cpp:342
static int cupsVersion()
Definition: qcups_p.h:75
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ setPrinterSelectionOption()

void QPrinter::setPrinterSelectionOption ( const QString option)

Sets the printer to use option to select the printer.

option is null by default (which implies that Qt should be smart enough to guess correctly), but it can be set to other values to use a specific printer selection option.

If the printer selection option is changed while the printer is active, the current print job may or may not be affected.

Warning
This function is not available on Windows.
See also
printerSelectionOption()

Referenced by supportedPaperSources().

◆ setPrintProgram()

void QPrinter::setPrintProgram ( const QString printProg)

Sets the name of the program that should do the print job to printProg.

On X11, this function sets the program to call with the PostScript output. On other platforms, it has no effect.

See also
printProgram()

Definition at line 1021 of file qprinter.cpp.

1022 {
1023  Q_D(QPrinter);
1024  ABORT_IF_ACTIVE("QPrinter::setPrintProgram");
1025  d->printEngine->setProperty(QPrintEngine::PPK_PrinterProgram, printProg);
1026  d->addToManualSetList(QPrintEngine::PPK_PrinterProgram);
1027 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ setPrintRange()

void QPrinter::setPrintRange ( PrintRange  range)

Sets the print range option in to be range.

Since
4.1

Definition at line 2247 of file qprinter.cpp.

Referenced by QPrintDialogPrivate::setupPrinter().

2248 {
2249  Q_D(QPrinter);
2250  d->printRange = QAbstractPrintDialog::PrintRange(range);
2251 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
PrintRange
Used to specify the print range selection option.
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ setResolution()

void QPrinter::setResolution ( int  dpi)

Requests that the printer prints at dpi or as near to dpi as possible.

This setting affects the coordinate system as returned by, for example QPainter::viewport().

This function must be called before QPainter::begin() to have an effect on all platforms.

See also
resolution() setPaperSize()

Definition at line 1562 of file qprinter.cpp.

1563 {
1564  Q_D(QPrinter);
1565  ABORT_IF_ACTIVE("QPrinter::setResolution");
1566  d->printEngine->setProperty(QPrintEngine::PPK_Resolution, dpi);
1567  d->addToManualSetList(QPrintEngine::PPK_Resolution);
1568 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ setWinPageSize()

void QPrinter::setWinPageSize ( int  pageSize)

Sets the page size to be used by the printer under Windows to pageSize.

Warning
This function is not portable so you may prefer to use setPaperSize() instead.
See also
winPageSize()

Definition at line 1912 of file qprinter.cpp.

1913 {
1914  Q_D(QPrinter);
1915  ABORT_IF_ACTIVE("QPrinter::setWinPageSize");
1916  d->printEngine->setProperty(QPrintEngine::PPK_WindowsPageSize, pageSize);
1917  d->addToManualSetList(QPrintEngine::PPK_WindowsPageSize);
1918 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
PageSize pageSize() const
Returns the printer page size.
Definition: qprinter.cpp:1187
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
#define ABORT_IF_ACTIVE(location)
Definition: qprinter.cpp:82

◆ supportedPaperSources()

QList< QPrinter::PaperSource > QPrinter::supportedPaperSources ( ) const

Returns the supported paper sizes for this printer.

The values will be either a value that matches an entry in the QPrinter::PaperSource enum or a driver spesific value. The driver spesific values are greater than the constant DMBIN_USER declared in wingdi.h.

Warning
This function is only available in windows.

Definition at line 2080 of file qprinter.cpp.

2081 {
2082  Q_D(const QPrinter);
2083  QVariant v = d->printEngine->property(QPrintEngine::PPK_PaperSources);
2084 
2085  QList<QVariant> variant_list = v.toList();
2087  for (int i=0; i<variant_list.size(); ++i)
2088  int_list << (QPrinter::PaperSource) variant_list.at(i).toInt();
2089 
2090  return int_list;
2091 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
#define Q_D(Class)
Definition: qglobal.h:2482
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
PaperSource
This enum type specifies what paper source QPrinter is to use.
Definition: qprinter.h:103

◆ supportedResolutions()

QList< int > QPrinter::supportedResolutions ( ) const

Returns a list of the resolutions (a list of dots-per-inch integers) that the printer says it supports.

For X11 where all printing is directly to postscript, this function will always return a one item list containing only the postscript resolution, i.e., 72 (72 dpi – but see PrinterMode).

Definition at line 1943 of file qprinter.cpp.

1944 {
1945  Q_D(const QPrinter);
1946  QList<QVariant> varlist
1947  = d->printEngine->property(QPrintEngine::PPK_SupportedResolutions).toList();
1948  QList<int> intlist;
1949  for (int i=0; i<varlist.size(); ++i)
1950  intlist << varlist.at(i).toInt();
1951  return intlist;
1952 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ supportsMultipleCopies()

bool QPrinter::supportsMultipleCopies ( ) const

Returns true if the printer supports printing multiple copies of the same document in one job; otherwise false is returned.

Since
4.7

On most systems this function will return true. However, on X11 systems that do not support CUPS, this function will return false. That means the application has to handle the number of copies by printing the same document the required number of times.

See also
setCopyCount(), copyCount()

Definition at line 1453 of file qprinter.cpp.

1454 {
1455  Q_D(const QPrinter);
1456  return d->printEngine->property(QPrintEngine::PPK_SupportsMultipleCopies).toBool();
1457 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ toPage()

int QPrinter::toPage ( ) const

Returns the number of the last page in a range of pages to be printed (the "to page" setting).

Since
4.1

Pages in a document are numbered according to the convention that the first page is page 1.

By default, this function returns a special value of 0, meaning that the "to page" setting is unset.

Note
If fromPage() and toPage() both return 0, this indicates that the whole document will be printed.

The programmer is responsible for reading this setting and printing accordingly.

See also
setFromTo(), fromPage()

Definition at line 2196 of file qprinter.cpp.

2197 {
2198  Q_D(const QPrinter);
2199  return d->toPage;
2200 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

◆ winPageSize()

int QPrinter::winPageSize ( ) const

Returns the page size used by the printer under Windows.

Warning
This function is not portable so you may prefer to use paperSize() instead.
See also
setWinPageSize()

Definition at line 1928 of file qprinter.cpp.

1929 {
1930  Q_D(const QPrinter);
1931  return d->printEngine->property(QPrintEngine::PPK_WindowsPageSize).toInt();
1932 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66

Friends and Related Functions

◆ QAbstractPrintDialog

friend class QAbstractPrintDialog
friend

Definition at line 301 of file qprinter.h.

◆ QAbstractPrintDialogPrivate

Definition at line 302 of file qprinter.h.

◆ QPageSetupWidget

friend class QPageSetupWidget
friend

Definition at line 305 of file qprinter.h.

◆ QPrintDialogPrivate

friend class QPrintDialogPrivate
friend

Definition at line 300 of file qprinter.h.

◆ QPrintPreviewWidgetPrivate

Definition at line 303 of file qprinter.h.

◆ QTextDocument

friend class QTextDocument
friend

Definition at line 304 of file qprinter.h.

Properties

◆ d_ptr

QScopedPointer<QPrinterPrivate> QPrinter::d_ptr
private

Definition at line 298 of file qprinter.h.

Referenced by QPrinter().


The documentation for this class was generated from the following files: