Results 1 to 3 of 3

Thread: drawing formatted QTextDocument

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Posts
    248
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    29
    Thanked 15 Times in 14 Posts

    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.

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
  •  
Qt is a trademark of The Qt Company.