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

Print Actions

KDEPrint provides a couple of predefined actions that you may use in your application to implement quickprint or export features. The related class is KPrintAction. Here's an excerpt of the header file for that class:

class KPrintAction : public KActionMenu
{
        Q_OBJECT
public:
	...
        static KPrintAction* exportAll(QWidget *parentWidget = 0, QObject *parent = 0, const char *name = 0);
	static KPrintAction* exportRegular(QWidget *parentWidget = 0, QObject *parent = 0, const char *name = 0);
        static KPrintAction* exportSpecial(QWidget *parentWidget = 0, QObject *parent = 0, const char *name = 0);

signals:
	void print(KPrinter*);
	...
};

The 3 static methods allow you to easily create KDEPrint related actions. When plugged into a toolbar or menubar, a popup menu will be inserted, which contains a list of printers. According to the method used, this list either includes: all printers; regular printers only; or special printers only. When one of those printers is selected in the popup menu, the signal print() is emitted, and the argument contains a KPrinter object that is preconfigured with all the default settings corresponding to the printer selected. You can then use that KPrinter object as usual, without calling the print dialog. The arguments are the following:

  • parentWidget : a widget that will be used as a parent for a potential file dialog (a file dialog is used when using a special printer that prints to a file)
  • parent : the parent of the action
  • name : the name of the action
(Click to enlarge)
// The top-level window
class ViewerWindow : public KMainWindow
{
	...
protected:
	void initActions();
	...
private:
	ViewerWidget	*m_viewer;
};

// The central widget of the top-level window
class ViewerWidget : public QWidget
{
	...
public slots:
	void slotQuickPrint(KPrinter*);
	...
};

void ViewerWindow::initActions()
{
	...
	// plugged in the toolbar
	KPrintAction	*paction = KPrintAction::exportRegular(m_viewer, actionCollection(), "export_regular");
	connect(paction, SIGNAL(print(KPrinter*)), m_viewer, SLOT(slotQuickPrint(KPrinter*)));
	paction->setIcon("filequickprint");
	paction->setDelayed(false);

	// plugged in the menubar
	paction = KPrintAction::exportSpecial(m_viewer, actionCollection(), "export_special");
	connect(paction, SIGNAL(print(KPrinter*)), m_viewer, SLOT(slotQuickPrint(KPrinter*)));
	paction->setDelayed(false);
	...
}

void ViewerWidget::slotQuickPrint(KPrinter *printer)
{
	// do the actual printing job
	doPrint(printer);

	// do not delete the KPrinter object, this is managed by the KPrintAction object
}

[ 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