• Skip to content
  • Skip to link menu
KDEPrint Homepage
  • KDEPrint Homepage / Developer Resources / Developer Tutorial
 
 

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 ]

Inform

Skip menu "Inform"
  • Home
  • KDE Home
  • News
  • Information
  • People
  • Mailing Lists
  • In The Media
  • Get Involved

KDEPrint

Skip menu "KDEPrint"
  • Overview
  • Screenshots
  • Hacks

Documentation

Skip menu "Documentation"
  • FAQ
  • KDEPrint Handbook
  • Tutorials
  • User Contributions

Downloads

Skip menu "Downloads"
  • Downloads

Develop

Skip menu "Develop"
  • Developer Resources
    • Information
    • Overview
    • Developer Tutorial
    • Online API Reference
  • Work plan

Global navigation links

  • KDE Home
  • KDE Accessibility Home
  • Description of Access Keys
  • Back to content
  • Back to menu

Search:


Maintained by printing.kde.org Webmaster
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal