|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.gui.QPrinter
public class QPrinter
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 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.setPaperSize()
tells QPrinter what paper 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.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.
QPrintDialog
, and Printing with Qt.
Nested Class Summary | |
---|---|
static class |
QPrinter.ColorMode
This enum type is used to indicate whether QPrinter should print in color or not. |
static class |
QPrinter.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). |
static class |
QPrinter.Orientation
This enum type (not to be confused with Orientation) is used to specify each page's orientation. |
static class |
QPrinter.OutputFormat
The OutputFormat enum is used to describe the format QPrinter should use for printing. |
static class |
QPrinter.PageOrder
This enum type is used by QPrinter to tell the application program how to print. |
static class |
QPrinter.PageSize
Use QPrinter::PaperSize instead. |
static class |
QPrinter.PaperSource
This enum type specifies what paper source QPrinter is to use. |
static class |
QPrinter.PrinterMode
This enum describes the mode the printer should work in. |
static class |
QPrinter.PrinterState
|
static class |
QPrinter.PrintRange
Used to specify the print range selection option. |
static class |
QPrinter.Unit
This enum type is used to specify the measurement unit for page and paper sizes. |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QPrinter()
Creates a new printer object with the given mode. |
|
QPrinter(QPrinter.PrinterMode mode)
Creates a new printer object with the given mode. |
|
QPrinter(QPrinterInfo printer)
Creates a new printer object with the given printer and mode. |
|
QPrinter(QPrinterInfo printer,
QPrinter.PrinterMode mode)
Creates a new printer object with the given printer and mode. |
Method Summary | |
---|---|
boolean |
abort()
Aborts the current print run. |
boolean |
collateCopies()
Returns true if collation is turned on when multiple copies is selected. |
QPrinter.ColorMode |
colorMode()
Returns the current color mode. |
java.lang.String |
creator()
Returns the name of the application that created the document. |
int |
depth()
Returns the bit depth (number of bit planes) of the paint device. |
java.lang.String |
docName()
Returns the document name. |
boolean |
doubleSidedPrinting()
Returns true if double side printing is enabled. |
QPrinter.DuplexMode |
duplex()
Returns the current duplex mode. |
boolean |
fontEmbeddingEnabled()
Returns true if font embedding is enabled. |
int |
fromPage()
Returns the number of the first page in a range of pages to be printed (the "from page" setting). |
boolean |
fullPage()
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. |
com.trolltech.qt.gui.QMarginsF |
getPageMargins(QPrinter.Unit unit)
Returns the page margins for this printer. |
int |
height()
Returns the height of the paint device in default coordinate system units (e. |
int |
heightMM()
Returns the height of the paint device in millimeters. |
boolean |
isValid()
Returns true if the printer currently selected is a valid printer in the system, or a pure PDF/PostScript printer; otherwise returns false. |
int |
logicalDpiX()
Returns the horizontal resolution of the device in dots per inch, which is used when computing font sizes. |
int |
logicalDpiY()
Returns the vertical resolution of the device in dots per inch, which is used when computing font sizes. |
int |
metric(QPaintDevice.PaintDeviceMetric arg__1)
Returns the metric information for the given paint device metric. |
boolean |
newPage()
Tells the printer to eject the current page and to continue printing on a new page. |
int |
numColors()
Returns the number of different colors available for the paint device. |
int |
numCopies()
Returns the number of copies to be printed. |
QPrinter.Orientation |
orientation()
Returns the orientation setting. |
java.lang.String |
outputFileName()
Returns the name of the output file. |
QPrinter.OutputFormat |
outputFormat()
Returns the output format for this printer. |
QPrinter.PageOrder |
pageOrder()
Returns the current page order. |
QRect |
pageRect()
Returns the page's rectangle; this is usually smaller than the paperRect() since the page normally has margins between its borders and the paper. |
QRectF |
pageRect(QPrinter.Unit arg__1)
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. |
QPrinter.PageSize |
pageSize()
Returns the printer page size. |
QPaintEngine |
paintEngine()
Returns a pointer to the paint engine used for drawing on the device. |
boolean |
paintingActive()
Returns true if the device is currently being painted on, i. |
QRect |
paperRect()
Returns the paper's rectangle; this is usually larger than the pageRect() . |
QRectF |
paperRect(QPrinter.Unit arg__1)
Returns the paper's rectangle in unit; this is usually larger than the pageRect() . |
QPrinter.PageSize |
paperSize()
Returns the printer paper size. |
QSizeF |
paperSize(QPrinter.Unit unit)
Returns the paper size in unit. |
QPrinter.PaperSource |
paperSource()
Returns the printer's paper source. |
int |
physicalDpiX()
Returns the horizontal resolution of the device in dots per inch. |
int |
physicalDpiY()
Returns the horizontal resolution of the device in dots per inch. |
QPrintEngine |
printEngine()
Returns the print engine used by the printer. |
java.lang.String |
printerName()
Returns the printer name. |
QPrinter.PrinterState |
printerState()
Returns the current state of the printer. |
java.lang.String |
printProgram()
Returns the name of the program that sends the print output to the printer. |
QPrinter.PrintRange |
printRange()
Returns the page range of the QPrinter. |
int |
resolution()
Returns the current assumed resolution of the printer, as set by setResolution() or by the printer driver. |
void |
setCollateCopies(boolean collate)
Sets the default value for collation checkbox when the print dialog appears. |
void |
setColorMode(QPrinter.ColorMode arg__1)
Sets the printer's color mode to newColorMode, which can be either Color or GrayScale. |
void |
setCreator(java.lang.String arg__1)
Sets the name of the application that created the document to creator. |
void |
setDocName(java.lang.String arg__1)
Sets the document name to name. |
void |
setDoubleSidedPrinting(boolean enable)
Enables double sided printing if doubleSided is true; otherwise disables it. |
void |
setDuplex(QPrinter.DuplexMode duplex)
Enables double sided printing based on the duplex mode. |
protected 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). |
void |
setFontEmbeddingEnabled(boolean enable)
Enabled or disables font embedding depending on enable. |
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. |
void |
setFullPage(boolean arg__1)
If fp is true, enables support for painting over the entire page; otherwise restricts painting to the printable area reported by the device. |
void |
setNumCopies(int arg__1)
Sets the number of copies to be printed to numCopies. |
void |
setOrientation(QPrinter.Orientation arg__1)
Sets the print orientation to orientation. |
void |
setOutputFileName(java.lang.String arg__1)
Sets the name of the output file to fileName. |
void |
setOutputFormat(QPrinter.OutputFormat format)
Sets the output format for this printer to format. |
void |
setPageMargins(double left,
double top,
double right,
double bottom,
QPrinter.Unit unit)
This function sets the left, top, right and bottom page margins for this printer. |
void |
setPageOrder(QPrinter.PageOrder arg__1)
Sets the page order to pageOrder. |
void |
setPageSize(QPrinter.PageSize arg__1)
Sets the printer page size based on newPageSize. |
void |
setPaperSize(QPrinter.PageSize arg__1)
Sets the printer paper size to arg_1 if that size is supported. |
void |
setPaperSize(QSizeF paperSize,
QPrinter.Unit unit)
Sets the paper size based on paperSize in unit. |
void |
setPaperSource(QPrinter.PaperSource arg__1)
Sets the paper source setting to source. |
void |
setPrinterName(java.lang.String arg__1)
Sets the printer name to name. |
void |
setPrintProgram(java.lang.String arg__1)
Sets the name of the program that should do the print job to printProg. |
void |
setPrintRange(QPrinter.PrintRange range)
Sets the print range option in to be range. |
void |
setResolution(int arg__1)
Requests that the printer prints at dpi or as near to dpi as possible. |
java.util.List |
supportedResolutions()
Returns a list of the resolutions (a list of dots-per-inch integers) that the printer says it supports. |
int |
toPage()
Returns the number of the last page in a range of pages to be printed (the "to page" setting). |
int |
width()
Returns the width of the paint device in default coordinate system units (e. |
int |
widthMM()
Returns the width of the paint device in millimeters. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QPrinter()
public QPrinter(QPrinter.PrinterMode mode)
public QPrinter(QPrinterInfo printer)
public QPrinter(QPrinterInfo printer, QPrinter.PrinterMode mode)
Method Detail |
---|
public final boolean abort()
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.
public final boolean collateCopies()
setCollateCopies()
.
public final QPrinter.ColorMode colorMode()
setColorMode()
.
public final java.lang.String creator()
setCreator()
.
public final int depth()
depth
in interface QPaintDeviceInterface
public final java.lang.String docName()
setDocName()
, and QPrintEngine::PrintEnginePropertyKey
.
public final boolean doubleSidedPrinting()
Currently this option is only supported on X11.
setDoubleSidedPrinting()
.
public final QPrinter.DuplexMode duplex()
Currently this option is only supported on X11.
setDuplex()
.
public final boolean fontEmbeddingEnabled()
Currently this option is only supported on X11.
setFontEmbeddingEnabled()
.
public final int fromPage()
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.
setFromTo()
, and toPage()
.
public final boolean fullPage()
See setFullPage()
for details and caveats.
setFullPage()
, and PaperSize
.
public final int height()
QPixmap
and QWidget
). heightMM()
.
height
in interface QPaintDeviceInterface
public final int heightMM()
height()
.
heightMM
in interface QPaintDeviceInterface
public final boolean isValid()
To detect other failures check the output of QPainter::begin()
or QPainter::nextPage().
The following code example is written in c++.
QPrinter printer; printer.setOutputFormat(QPrinter::PdfFormat); 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();
setPrinterName()
.
public final int logicalDpiX()
widthMM()
. Note that if the logicalDpiX()
doesn't equal the physicalDpiX()
, the corresponding QPaintEngine
must handle the resolution mapping.
logicalDpiY()
, and physicalDpiX()
.
logicalDpiX
in interface QPaintDeviceInterface
public final int logicalDpiY()
heightMM()
. Note that if the logicalDpiY()
doesn't equal the physicalDpiY()
, the corresponding QPaintEngine
must handle the resolution mapping.
logicalDpiX()
, and physicalDpiY()
.
logicalDpiY
in interface QPaintDeviceInterface
public final boolean newPage()
Calling newPage()
on an inactive QPrinter object will always fail.
public final int numColors()
numColors
in interface QPaintDeviceInterface
public final int numCopies()
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.
setNumCopies()
.
public final QPrinter.Orientation orientation()
QPrinter::Portrait
. setOrientation()
.
public final java.lang.String outputFileName()
setOutputFileName()
, and QPrintEngine::PrintEnginePropertyKey
.
public final QPrinter.OutputFormat outputFormat()
setOutputFormat()
.
public final QPrinter.PageOrder pageOrder()
The default page order is FirstPageFirst.
setPageOrder()
.
public final QRect pageRect()
paperRect()
since the page normally has margins between its borders and the paper. The unit of the returned rectangle is DevicePixel
.
paperSize()
.
public final QRectF pageRect(QPrinter.Unit arg__1)
paperRect()
since the page normally has margins between its borders and the paper. paperSize()
.
public final QPrinter.PageSize pageSize()
Use paperSize()
instead.
public final boolean paintingActive()
QPainter::begin()
but not yet called QPainter::end()
for this device; otherwise returns false. QPainter::isActive()
.
paintingActive
in interface QPaintDeviceInterface
public final QRect paperRect()
pageRect()
. The unit of the returned rectangle is DevicePixel
.
pageRect()
.
public final QRectF paperRect(QPrinter.Unit arg__1)
pageRect()
. pageRect()
.
public final QPrinter.PageSize paperSize()
setPaperSize()
, pageRect()
, and paperRect()
.
public final QSizeF paperSize(QPrinter.Unit unit)
setPaperSize()
.
public final QPrinter.PaperSource paperSource()
setPaperSource()
.
public final int physicalDpiX()
Note that if the physicalDpiX()
doesn't equal the logicalDpiX()
, the corresponding QPaintEngine
must handle the resolution mapping.
physicalDpiY()
, and logicalDpiX()
.
physicalDpiX
in interface QPaintDeviceInterface
public final int physicalDpiY()
Note that if the physicalDpiY()
doesn't equal the logicalDpiY()
, the corresponding QPaintEngine
must handle the resolution mapping.
physicalDpiX()
, and logicalDpiY()
.
physicalDpiY
in interface QPaintDeviceInterface
public final QPrintEngine printEngine()
public final java.lang.String printProgram()
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.
setPrintProgram()
, and setPrinterSelectionOption().
public final QPrinter.PrintRange printRange()
setPrintRange()
.
public final java.lang.String printerName()
setPrinterName()
.
public final QPrinter.PrinterState printerState()
public final int resolution()
setResolution()
or by the printer driver. setResolution()
.
public final void setCollateCopies(boolean collate)
collateCopies()
.
public final void setColorMode(QPrinter.ColorMode arg__1)
colorMode()
.
public final void setCreator(java.lang.String arg__1)
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.
creator()
.
public final void setDocName(java.lang.String arg__1)
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.
docName()
, and QPrintEngine::PrintEnginePropertyKey
.
public final void setDoubleSidedPrinting(boolean enable)
Currently this option is only supported on X11.
doubleSidedPrinting()
.
public final void setDuplex(QPrinter.DuplexMode duplex)
Currently this option is only supported on X11.
duplex()
.
protected final void setEngines(QPrintEngine printEngine, QPaintEngine paintEngine)
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.
printEngine()
, paintEngine()
, and setOutputFormat()
.
public final void setFontEmbeddingEnabled(boolean enable)
Currently this option is only supported on X11.
fontEmbeddingEnabled()
.
public final void setFromTo(int fromPage, int toPage)
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().
fromPage()
, and toPage()
.
public final void setFullPage(boolean arg__1)
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.
fullPage()
, setPaperSize()
, width()
, height()
, and Printing with Qt.
public final void setNumCopies(int arg__1)
The printer driver reads this setting and prints the specified number of copies.
numCopies()
.
public final void setOrientation(QPrinter.Orientation arg__1)
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.
orientation()
.
public final void setOutputFileName(java.lang.String arg__1)
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
.
outputFileName()
, setOutputToFile(), and setOutputFormat()
.
public final void setOutputFormat(QPrinter.OutputFormat format)
outputFormat()
.
public final void setPageMargins(double left, double top, double right, double bottom, QPrinter.Unit unit)
public final void setPageOrder(QPrinter.PageOrder arg__1)
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.
pageOrder()
.
public final void setPageSize(QPrinter.PageSize arg__1)
Use setPaperSize()
instead.
public final void setPaperSize(QPrinter.PageSize arg__1)
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.
paperSize()
, PaperSize
, setFullPage()
, setResolution()
, pageRect()
, and paperRect()
.
public final void setPaperSize(QSizeF paperSize, QPrinter.Unit unit)
paperSize()
.
public final void setPaperSource(QPrinter.PaperSource arg__1)
Windows only: This option can be changed while printing and will take effect from the next call to newPage()
paperSource()
.
public final void setPrintProgram(java.lang.String arg__1)
On X11, this function sets the program to call with the PostScript output. On other platforms, it has no effect.
printProgram()
.
public final void setPrintRange(QPrinter.PrintRange range)
printRange()
.
public final void setPrinterName(java.lang.String arg__1)
printerName()
, and isValid()
.
public final void setResolution(int arg__1)
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.
resolution()
, and setPaperSize()
.
public final java.util.List supportedResolutions()
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
).
public final int toPage()
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.
setFromTo()
, and fromPage()
.
public final int width()
QPixmap
and QWidget
). widthMM()
.
width
in interface QPaintDeviceInterface
public final int widthMM()
width()
.
widthMM
in interface QPaintDeviceInterface
public int metric(QPaintDevice.PaintDeviceMetric arg__1)
PaintDeviceMetric
.
metric
in interface QPaintDeviceInterface
public QPaintEngine paintEngine()
paintEngine
in interface QPaintDeviceInterface
public final com.trolltech.qt.gui.QMarginsF getPageMargins(QPrinter.Unit unit)
unit
- Specifies the unit of the returned margins.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |