Results 1 to 3 of 3

Thread: QtextDocument-ItemDelegate and Painting

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Posts
    44
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default QtextDocument-ItemDelegate and Painting

    Hello Forum! I am having trouble painting a QTextDocument inside a StyledItemDelegate. I am painting all delegates with paint.drawText EXCEPT delegates with rich text contents. Those I am painting with QTextDocument. I am using the same process for printing. In both cases I get the text properly painted but it is putting a blank area before the next delegate paint event. The problem seems to be paint.translate. If I use it, I get properly printed text, but a blank area. If I don't use it, I get no text painted, but the size of the blank area is correct. If I paint a rectangle using painter.drawRect(), it draws a rectangle under the rich text around where the text SHOULD go, and it's the correct size. It's like the painter goes off into some alternate reality, and it doesn't seem to matter how I access the drawing function. Here is the process I am using and code:
    Set Size Hint using:
    Qt Code:
    1. q_txt.setDefaultFont( iter.Data()->GetColumnFont());
    2. q_txt.setTextWidth( (float)iter.Data()->GetWidth() );
    3. q_txt.setDocumentMargin( 0 );
    4. //set row height equal to the tallest text in the line
    5. QString col_text( (char*)iter.Data()->GetColumnText() );
    6. if( col_text.contains( "<!DOCTYPE html" ) )
    7. {
    8. q_txt.setHtml( col_text );
    9. }
    10. else
    11. q_txt.setPlainText( col_text );
    12.  
    13. if( height < q_txt.size().height() )
    14. height = q_txt.size().height();
    To copy to clipboard, switch view to plain text mode 

    And then I try to paint it in the delegate's paint event with (I left in some of my attempts commented out) this code:
    Qt Code:
    1. q_txt.setDocumentMargin( 0 );
    2. q_txt.setHtml( col_text );
    3. q_txt.setTextWidth( iter.Data()->GetWidth() );
    4. //painter->setViewport( r.x(), r.y(), r.width(), r.height());
    5. painter->translate( r.x(),r.y());
    6. q_txt.drawContents( painter );
    7. // QAbstractTextDocumentLayout::PaintContext context;
    8. // q_txt.setPageSize( arect.size());
    9. // painter->translate( arect.x(),arect.y());
    10. // q_txt.documentLayout()->draw(painter, context);
    11.  
    12. painter->restore();
    13. // painter->drawRect( r );
    To copy to clipboard, switch view to plain text mode 
    Yes, I know this is something stupid and I'm too dense to 'get it', but if someone has the answer, it would make my day!! Thanks in advance!

  2. The following user says thank you to LynneV for this useful post:

    kornerr (14th November 2010)

Similar Threads

  1. Display ItemDelegate Editor always
    By gast23 in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2010, 05:33
  2. QTreeView and itemDelegate code
    By alexandernst in forum Newbie
    Replies: 1
    Last Post: 22nd April 2010, 18:00
  3. Can I use a QWidget as a renderer in an ItemDelegate?
    By boblebel in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2009, 21:03
  4. Color table row with ItemDelegate
    By dexjam in forum Newbie
    Replies: 8
    Last Post: 29th June 2006, 13:56
  5. Replies: 0
    Last Post: 28th June 2006, 21:49

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.