Results 1 to 3 of 3

Thread: How to use QPrinter without QPrintDialog?

  1. #1
    Join Date
    Apr 2006
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to use QPrinter without QPrintDialog?

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: How to use QPrinter without QPrintDialog?

    a life without programming is like an empty bottle

  3. #3
    Join Date
    Mar 2006
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to use QPrinter without QPrintDialog?

    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..

    Qt Code:
    1. QTextDocument document;
    2. document.setHtml("testing");
    3.  
    4. QPrinter printer;
    5. printer.setPrinterName("desired printer name here");
    6. QPrintDialog dialog(&printer, this);
    7. document.print(&printer);
    To copy to clipboard, switch view to plain text mode 

    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
    Qt Code:
    1. if (dialog.exec() == QDialog::Accepted)
    To copy to clipboard, switch view to plain text mode 
    before the document.print

Similar Threads

  1. QPrinter for QTextEdit
    By sms in forum Qt Programming
    Replies: 0
    Last Post: 17th July 2008, 16:21
  2. QPrinter on QGraphicsScene Border Problem
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 15:49
  3. QPrinter problems
    By Teuniz in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2007, 08:51
  4. QPrinter on Solaris
    By ToddAtWSU in forum Qt Programming
    Replies: 4
    Last Post: 24th October 2006, 20:29
  5. QPrintDialog problem
    By gesslar in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 04:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.