Results 1 to 3 of 3

Thread: Printing with QTextEdit

  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Printing with QTextEdit

    Hello guys,
    Is there any problem with the following code snippet?
    The contents of the QTextEdit are printed on paper properly but after the printing
    is done, the QTextEdit disappears completely from the canvas i.e the contents on the
    canvas disappears. Is there anything I'm missing in the below code?

    I suppose once the layout of the QTextEdit is changed I need to reset it back to
    original form. But no luck. Can someone please help me with this.

    Qt Code:
    1. void myClass::printEditorContents( QRect headerRect, QPainter &paint )
    2. {
    3. QAbstractTextDocumentLayout *layout = _textEdit->document()->documentLayout();
    4. _textEdit->document()->setDefaultFont(defaultFont);
    5.  
    6. paint.save();
    7.  
    8. paint.setFont(defaultFont);
    9. QPaintDevice *pd = layout->paintDevice();
    10. layout->setPaintDevice(paint.device());
    11.  
    12. QTextFrameFormat fmt = _textEdit->document()->rootFrame()->frameFormat();
    13. fmt.setMargin(margin.x());
    14. fmt.setHeight(headerRect.height());
    15. fmt.setWidth(headerRect.width());
    16.  
    17. _textEdit->document()->rootFrame()->setFrameFormat(fmt);
    18. _textEdit->document()->drawContents(&paint);
    19. layout->setPaintDevice(pd);
    20. paint.restore();
    21. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance.

  2. #2
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing with QTextEdit

    I hope I'm clear if not please let me....

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Printing with QTextEdit

    Why don't you use QTextDocument::print()?

Similar Threads

  1. Printing problem in windows
    By joseph in forum Qt Programming
    Replies: 6
    Last Post: 12th July 2007, 08:04
  2. Re-implement mouse events of QTextEdit
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2006, 16:55
  3. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  4. Obtaining clean (x)html from QTextEdit
    By ccf_h in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2006, 14:47

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.