Results 1 to 6 of 6

Thread: Printing a textdocument via QStringLists

  1. #1
    Join Date
    May 2012
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Printing a textdocument via QStringLists

    Hello all,

    I feel very confused about printing.

    Everywhere I went, it was too confusing figuring out where to start when to print out a simple document.

    I wanted to print a document like this:

    I press the print button, it opens up a dialog checking pdf or not.

    I have this QStringList of all Items sorted in my inventory


    QStringList items:

    each element looked like this: "title,type,author,datePublished"

    what I wanted to do was print out the report to a pdf in a way that looked like this:

    LIBRARY ITEMS : DATE

    items[0]
    items[1]
    items[2]
    items[3]
    items[4]

    etc..

    But all of this about QPainter, QTextdocuments, QPrintPreviewDialog/Widget (list goes on and on).... not to mention every attempt i have done ends saying the Qpainter hasn't started(isnt that what the begin method is for!?)

    I sound like an idiot, I know.

    But if anyone could help with this, it would be a great help.

    I could use some help in how to tell when to go to the next page... i could never understand that from the docs

    all i need is a general guideline on how to implement this simple list via printing out qstringlists to what seems to be either the painter directly or document or.... honestly i dont know. I'm so confused.

    Thanks for those who help,
    gamenovice

    **let me know if i was not clear

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Printing a textdocument via QStringLists

    How about you show us what you have that gives you there error you describe and then we can start to help.

    Two obvious approaches:
    • Create a QTextDocument, using QTextCursor or by generating and importing HTML, and then use its print() function
    • Manually paginate your data and render it line by line to a QPainter attached to the QPrinter.

  3. The following user says thank you to ChrisW67 for this useful post:

    gamenovice (8th May 2012)

  4. #3
    Join Date
    May 2012
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Printing a textdocument via QStringLists

    about that first option:

    could I simply edit my text via the Textcursor, and when everything is done I can call the print function without anything like the paint event?

    also, could you embed html tags into the insert text as well as the '\n' character sequence, or would that work?
    (I know there is a sethtml function, but I'm curious if insertText can support on the fly html)
    Last edited by gamenovice; 8th May 2012 at 19:30.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Printing a textdocument via QStringLists

    Quote Originally Posted by gamenovice View Post
    could I simply edit my text via the Textcursor, and when everything is done I can call the print function without anything like the paint event?
    Yes.
    also, could you embed html tags into the insert text as well as the '\n' character sequence, or would that work?
    (I know there is a sethtml function, but I'm curious if insertText can support on the fly html)
    QTextCursor::insertHTML() looks promising.

    If you haven't already, have a read of Rich Text Processing

    If you can get hold of a copy of Advanced Qt Programming by Summerfield you will find a whole chapter that does just this sort of thing.

  6. The following user says thank you to ChrisW67 for this useful post:

    gamenovice (9th May 2012)

  7. #5
    Join Date
    May 2012
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Printing a textdocument via QStringLists

    one more thing, is there anyway to get a QTextDocument to go to a printPreview and then via dialog, go on to actual printing?

    Thank you for your help btw.

  8. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Printing a textdocument via QStringLists

    Yes. The QPrintPreviewDialog::paintRequested() (QPrintPreviewWidget) signal passes a QPrinter* that renders to the preview. Connect that signal to a slot that calls QTextDocument::print() passing the QPrinter*.

Similar Threads

  1. Printing In QT
    By Splatify in forum Newbie
    Replies: 1
    Last Post: 8th March 2011, 00:09
  2. sorting two QStringLists simultaneously
    By hokie2012 in forum Qt Programming
    Replies: 7
    Last Post: 6th September 2010, 07:45
  3. How to print textDocument on virtual printer?
    By mSergey in forum Qt Programming
    Replies: 8
    Last Post: 17th January 2008, 13:49
  4. Printing to PDF
    By vermarajeev in forum Qt Programming
    Replies: 8
    Last Post: 11th December 2006, 03:25
  5. Qt Printing on .ps
    By vratojr in forum Qt Programming
    Replies: 3
    Last Post: 18th February 2006, 23:22

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.