PDA

View Full Version : How to use QPrinter without QPrintDialog?



pascal456
7th April 2006, 09:34
Dear all,

I'd like to use QPrinter without a call to QPrintDialog. The following sequence works:

QPrinter prt;
QPrintDialog dlg(&prt,this);
if(dlg.exec() == QDialog::Accepted)
{
// do the printing here
}

However, I'd like to have QPrinter send its postscript output to "kprinter" (or another program of my choice), at least in the unix version of my app.

I tried not to call QPrintDialog but to use
prt.setPrintProgram("kprinter");

but unfortunately this does not do anything.

Thanks for your help

Pascal

zlatko
7th April 2006, 09:37
Few minutes old thread (http://www.qtcentre.org/forum/showthread.php?t=1682) :)

Byngl
15th November 2006, 19:57
The linked thread doesn't pertain to Qt4, but I think I've found a work-around (on WinXP Home with Qt 4.2.1 at least). You still need to use QPrintDialog, but you don't need to actually display it..



QTextDocument document;
document.setHtml("testing");

QPrinter printer;
printer.setPrinterName("desired printer name here");
QPrintDialog dialog(&printer, this);
document.print(&printer);

If I omit the setPrinterName call, I get output to the default printer.

I've also noticed that if I try to print to "Generic / Text Only", I get nothing in the resulting file except for CR's and LF's. The supplied code gives me 1 CR and 50 LFs. The output is the same even if I add
if (dialog.exec() == QDialog::Accepted) before the document.print