Automatic Preview
The class KPrinter provides easy to use facilities for applications to implement a preview mechanism. KDEPrint contains a preview mechanism that can be used directly by your application with minimal code addition. The steps required to do that are the following:
- create a KPrinter object
- modify the KPrinter object for preview only mode
- paint on the KPrinter object as usual
The only difference with normal use of KPrinter (as shown previously) is that an additional flag is set in the KPrinter object (by calling KPrinter::setPreviewOnly(true)) and that the print dialog is not called. By using this additional flag, the preview dialog will be automatically called on QPainter::end() with the single possibility to close it without going further (like it would happen when cancelling printing when previewing). The following code example demonstrates how to use that feature.
![]() |
(Click to enlarge) |
// let's imagine that this slot is connected to a "Preview" action that you created
// and plugged into the toolbar and/or menubar.
void ViewerWidget::slotPreview()
{
// create the KPrinter object: we choose here to not use the 'restore'
// flag because we want to use a clean, independent KPrinter object, but
// this may be different in other applications.
KPrinter printer(false);
// define the KPrinter object as preview-only
printer.setPreviewOnly(true);
// do the actual printing job
doPrint(&printer);
}
|
[ Edit ]
KDEPrint Homepage
