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:
q_txt.setDefaultFont( iter.Data()->GetColumnFont());
q_txt.setTextWidth( (float)iter.Data()->GetWidth() );
q_txt.setDocumentMargin( 0 );
//set row height equal to the tallest text in the line
QString col_text
( (char*)iter.
Data()->GetColumnText
() );
if( col_text.contains( "<!DOCTYPE html" ) )
{
q_txt.setHtml( col_text );
}
else
q_txt.setPlainText( col_text );
if( height < q_txt.size().height() )
height = q_txt.size().height();
q_txt.setDefaultFont( iter.Data()->GetColumnFont());
q_txt.setTextWidth( (float)iter.Data()->GetWidth() );
q_txt.setDocumentMargin( 0 );
//set row height equal to the tallest text in the line
QString col_text( (char*)iter.Data()->GetColumnText() );
if( col_text.contains( "<!DOCTYPE html" ) )
{
q_txt.setHtml( col_text );
}
else
q_txt.setPlainText( col_text );
if( height < q_txt.size().height() )
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:
q_txt.setDocumentMargin( 0 );
q_txt.setHtml( col_text );
q_txt.setTextWidth( iter.Data()->GetWidth() );
//painter->setViewport( r.x(), r.y(), r.width(), r.height());
painter->translate( r.x(),r.y());
q_txt.drawContents( painter );
// QAbstractTextDocumentLayout::PaintContext context;
// q_txt.setPageSize( arect.size());
// painter->translate( arect.x(),arect.y());
// q_txt.documentLayout()->draw(painter, context);
painter->restore();
// painter->drawRect( r );
q_txt.setDocumentMargin( 0 );
q_txt.setHtml( col_text );
q_txt.setTextWidth( iter.Data()->GetWidth() );
//painter->setViewport( r.x(), r.y(), r.width(), r.height());
painter->translate( r.x(),r.y());
q_txt.drawContents( painter );
// QAbstractTextDocumentLayout::PaintContext context;
// q_txt.setPageSize( arect.size());
// painter->translate( arect.x(),arect.y());
// q_txt.documentLayout()->draw(painter, context);
painter->restore();
// 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!
Bookmarks