[Qt-interest] QStaticText class and multiline text

Constantin Makshin cmakshin at gmail.com
Wed Sep 1 16:58:53 CEST 2010


Thanks, Atlant, using HTML solved the problem. But I find it strange that such a simple feature like linebreaks doesn't work in "plain text" mode and requires switching to HTML.

Also during playing with QStaticText I got other problems:
1) text alignment — I use QStaticText::size() to get text's bounding box and center it in the flowchart block and some combinations of QStaticText parameters result in weird alignment bugs;
2) rendering bugs — each flowchart block has a number drawn using large font and sometimes there are "trails" left by this text when the flowchart is scrolled upwards (for some reason other scrolling directions [seem to] work OK).

I've managed to find a workaround for (1) by sticking to "safe" parameters that seem to give correct results, but I don't know what to do with (2). Pre-4.7 method of rendering text with QPainter::drawText() had neither of these problems, but I'm not sure if (2) is really caused by something in QStaticText or something "broke" in Qt 4.7. I'll try to test it a bit more and let you know my findings.

Thank you.

On Monday 30 August 2010 16:22:31 Atlant Schmidt wrote:
> Constantin:
> 
>   HTML formatting should work, no?
> 
>   So use <br/> tags in place of your \n characters.
> 
> 
> 
>   http://doc.trolltech.com/4.7-snapshot/qstatictext.html
> 
>     For extra convenience, it is possible to apply formatting
>     to the text using the HTML subset supported by QTextDocument
>     QStaticText will attempt to guess the format of the input
>     text using Qt::mightBeRichText(), and interpret it as rich
>     text if this function returns true. To force QStaticText to
>     display its contents as either plain text or rich text, use
>     the function QStaticText::setTextFormat() and pass in,
>     respectively, Qt::PlainText and Qt::RichText.
> 
> 
>                             Atlant
> 
> 
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Constantin Makshin
> Sent: Sunday, August 29, 2010 6:17 AM
> To: Qt Interest
> Subject: [Qt-interest] QStaticText class and multiline text
> 
> Hi!
> 
> I have an application that works with data shown to the user in the form of flowcharts. Since these flowcharts contain relatively high amount of text and that text doesn't change too often, I thought using QStaticText could improve application's performance (currently text is drawn by QPainter::drawText() and I haven't had any performance-related problems so far). But when I tried to use it, I discovered that QStaticText doesn't [seem to] support text with explicit linebreaks and draws empty squares in place of '\n' characters.
> 
> Is this a bug or intended behavior? Are there any plans to add support of multiline text to QStaticText and QPainter::drawStaticText()?
> 
> I use Qt 4.7.0 RC1 at the moment, if that's important.



More information about the Qt-interest-old mailing list