Qt World Summit: Register Today!

Qt::TextFlag vs. QTextOption

  • I am slightly confused about the use of Qt::TextFlag versus QTextOption.

    I am preparing a QStaticText, that can either be single line or multi line.

    QStaticText::size() is unreliable in certain circumstances (so far, it returns incorrect results on a Windows 7 machine, with the font size given in Pixels, not Point).

    Therefore, I am trying to calculate the size using good old QFontMetrics.

    Now, QStaticText uses the QTextOption object, so I have a QTextOption object ready for use.
    However, QFontMetrics wants Qt::TextFlag.

    Is there a way to translate one to the other, or do I have to do it by hand (as far as the flags match at all)?

  • The big difference between both approach is the technology used:
    QStaticText use internally a QTextDocument to layout, so mainly the interface need a QTextCharFormat and a QTextOption to format the text (mainly rich text).
    In the case of the font based fonction like, drawText() or QFontMetrics class they are using a simplier layout mechanism, which needs just the align and QTextFormat (mainly single font).
    Mainly it's 2 differents approachs to render the text.

Log in to reply