Results 1 to 8 of 8

Thread: Painting Rich Text

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2006
    Posts
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: Painting Rich Text

    Thanks for the tip, Jacek.

    However, I can't get anything to appear via QAbstractTextDocumentLayout::draw(). For example, here is some test code that doesn't work:

    Qt Code:
    1. QTextDocument td( "test" );
    2. QAbstractTextDocumentLayout::PaintContext ctx;
    3. ctx.clip = QRectF( 0, 0, 400, 100 );
    4. qPainter->drawRect( ctx.clip ); // Test that I'm drawing in the right area
    5. td.documentLayout()->draw( qPainter, ctx );
    To copy to clipboard, switch view to plain text mode 

    The clip rectangle gets drawn properly, but no text is drawn.

    I've tried looking at how QTextEdit draws its QTextDocument, and I can't see anything significantly different to what I am doing, but obviously there must be something..

    Any ideas?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Painting Rich Text

    Add:
    Qt Code:
    1. td.setPageSize( QSizeF( 400, 100 ) );
    To copy to clipboard, switch view to plain text mode 
    Probably you need also:
    Qt Code:
    1. td.documentLayout()->setPaintDevice( this );
    To copy to clipboard, switch view to plain text mode 

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

    xanthine (15th April 2006)

  4. #3
    Join Date
    Apr 2006
    Posts
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: Painting Rich Text

    It's all working perfectly now. Thanks for all your help!

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Rich text in QGraphicsTextItem
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2008, 20:08
  3. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  4. Replies: 3
    Last Post: 13th December 2007, 16:10
  5. Rich Text Format
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 4th October 2006, 10:53

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.