Results 1 to 2 of 2

Thread: Printing In QT

  1. #1
    Join Date
    Oct 2010
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Printing In QT

    Hi all I have multiple elements I wish to print.

    I have a label, a textedit and I have a tableview full of data which I wish to print. I assume that I need to add all of these into a single document and then print the document. I was wondering how to add all of these items to a single document and then print it?

    So far the code I have is:

    Qt Code:
    1. //Select a printer
    2. QPrinter printer;
    3.  
    4. QPrintDialog *dialog = new QPrintDialog(&printer, this);
    5. dialog->setWindowTitle("Print Document");
    6. dialog->exec();
    7.  
    8. //Create a text document:
    9. // I think I need some code here which adds all the elements.
    10. //This is the part I'm getting confused with.
    11.  
    12. //Print the document
    13. doc.print(&printer);
    To copy to clipboard, switch view to plain text mode 

    Could someone please give me some guidance, perhaps some example code?


    Thanks for your time and trouble

  2. #2
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Printing In QT

    Splatify - I don't know how other folks print, but I am printing labels like this:
    Qt Code:
    1. QFont printFont("courier", 10);
    2. printFont.setFixedPitch(TRUE);
    3.  
    4. QPainter painter(&printer);
    5. painter.setPen(Qt::black);
    6. painter.setFont(printFont);
    7.  
    8. int x = 1;
    9. int y = 20;
    10. for (int i = 0; i < list.size(); i++)
    11. {
    12. painter.drawText(x, y, list[i]);
    13. y = y + 15;
    14. }
    To copy to clipboard, switch view to plain text mode 
    The list is built from a database query by appending the query values to a QStingList. It works fine for me. You should be able to use the same type of code by just appending whatever you need to your list.

    This code comes after my call to the QPrintDialog.

Similar Threads

  1. Printing Qt
    By IsoArska in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2010, 13:10
  2. Qwt Printing
    By giusepped in forum Qwt
    Replies: 3
    Last Post: 12th December 2008, 09:25
  3. Printing to PDF
    By vermarajeev in forum Qt Programming
    Replies: 8
    Last Post: 11th December 2006, 04:25
  4. Re: Printing in Qt
    By Jimmy2775 in forum Newbie
    Replies: 3
    Last Post: 13th July 2006, 00:00
  5. Qt Printing on .ps
    By vratojr in forum Qt Programming
    Replies: 3
    Last Post: 19th February 2006, 00:22

Tags for this Thread

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.