Results 1 to 3 of 3

Thread: drawing formatted QTextDocument

  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default drawing formatted QTextDocument

    I need to render a QTextDocument formatted by a QSyntaxHighlighter to a raw window.
    I figured a way via


    Qt Code:
    1. painter->translate(x, y);
    2. QAbstractTextDocumentLayout::PaintContext cont;
    3. document()->documentLayout()->draw(painter, cont);
    To copy to clipboard, switch view to plain text mode 


    but this doesnt allow for centering it in a QRect.
    How could i do it like drawing a plain string with a QPainter?


    Qt Code:
    1. painter->drawText(x,y,w,h,Qt::AlignLeft, mystr);
    To copy to clipboard, switch view to plain text mode 



    thanks,


    edit:
    for example, this doesnt work:
    Qt Code:
    1. document()->drawContents(painter, QRect(x,y,w,h));
    To copy to clipboard, switch view to plain text mode 

    edit2:
    Another problem is that the code in the very first code box doesnt use the font selected into QPainter...
    Last edited by tuli; 14th July 2012 at 14:48.

  2. #2
    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: drawing formatted QTextDocument

    Set the width of the document prior to using the layout.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: drawing formatted QTextDocument

    that did the trick, thanks!



    posts: 26,692
    respect! O.O
    Last edited by tuli; 14th July 2012 at 17:15.

Similar Threads

  1. Qt Linguist HTML Formatted fields, really just not supported?
    By mortoray in forum Qt Tools
    Replies: 1
    Last Post: 23rd December 2010, 12:58
  2. std formatted string with QTextEdit
    By nileshsince1980 in forum Qt Programming
    Replies: 14
    Last Post: 25th February 2010, 06:46
  3. Drawing QImage inside QTextDocument
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 13th April 2009, 07:52
  4. Drawing Rich Formatted Text with QPainter
    By millsks in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2009, 19:59
  5. formatted text in QTreeWidgetItem
    By swiety in forum Qt Programming
    Replies: 1
    Last Post: 30th October 2007, 16:26

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.