Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QPrinter Class Reference

Inheritance diagram for QPrinter:


List of all members.

Detailed Description

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

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.

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

The most important parameters are: setOrientation() tells QPrinter which page orientation to use. setPageSize() tells QPrinter what page size to expect from the printer. setResolution() tells QPrinter what resolution you wish the printer to provide, in dots per inch (DPI). setFullPage() tells QPrinter whether you want to deal with the full page or just with the part the printer can draw on. setNumCopies() tells QPrinter how many copies of the document it should print.

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 64 of file qprinter.h.

Public Types

enum  ColorMode { GrayScale, Color }
enum  Orientation { Portrait, Landscape }
enum  OutputFormat { NativeFormat, PdfFormat, PostScriptFormat }
enum  PageOrder { FirstPageFirst, LastPageFirst }
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
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
enum  PaperSource {
  OnlyOne, Lower, Middle, Manual,
  Envelope, EnvelopeManual, Auto, Tractor,
  SmallFormat, LargeFormat, LargeCapacity, Cassette,
  FormSource, MaxPageSource
enum  PrinterMode { ScreenResolution, PrinterResolution, HighResolution }
enum  PrinterState { Idle, Active, Aborted, Error }
enum  PrintRange { AllPages, Selection, PageRange }

Public Member Functions

bool abort ()
bool collateCopies () const
ColorMode colorMode () const
QString creator () const
int depth () const
int devType () const
QString docName () const
bool doubleSidedPrinting () const
bool fontEmbeddingEnabled () const
int fromPage () const
bool fullPage () const
int height () const
int heightMM () const
int logicalDpiX () const
int logicalDpiY () const
bool newPage ()
int numColors () const
int numCopies () const
Orientation orientation () const
QString outputFileName () const
OutputFormat outputFormat () const
PageOrder pageOrder () const
QRect pageRect () const
PageSize pageSize () const
QPaintEnginepaintEngine () const
bool paintingActive () const
QRect paperRect () const
PaperSource paperSource () const
int physicalDpiX () const
int physicalDpiY () const
QPrintEngineprintEngine () const
QString printerName () const
QString printerSelectionOption () const
PrinterState printerState () const
QString printProgram () const
PrintRange printRange () const
 QPrinter (PrinterMode mode=ScreenResolution)
int resolution () const
void setCollateCopies (bool collate)
void setColorMode (ColorMode)
void setCreator (const QString &)
void setDocName (const QString &)
void setDoubleSidedPrinting (bool enable)
void setFontEmbeddingEnabled (bool enable)
void setFromTo (int fromPage, int toPage)
void setFullPage (bool)
void setNumCopies (int)
void setOrientation (Orientation)
void setOutputFileName (const QString &)
void setOutputFormat (OutputFormat format)
void setPageOrder (PageOrder)
void setPageSize (PageSize)
void setPaperSource (PaperSource)
void setPrinterName (const QString &)
void setPrinterSelectionOption (const QString &)
void setPrintProgram (const QString &)
void setPrintRange (PrintRange range)
void setResolution (int)
QList< int > supportedResolutions () const
int toPage () const
int width () const
int widthMM () const
 ~QPrinter ()

Protected Member Functions

int metric (PaintDeviceMetric) const
void setEngines (QPrintEngine *printEngine, QPaintEngine *paintEngine)

Protected Attributes

ushort painters

Private Attributes

QPrinterPrivate * d_ptr


class QAbstractPrintDialog
class QPrintDialogWin

Related Functions

(Note that these are not member functions.)

const Q_GUI_EXPORT QX11Infoqt_x11Info (const QPaintDevice *pd)

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

Generated by  Doxygen 1.6.0   Back to index