Detect Rich Text in QML

  • Is there an easy way for a Text element to know if its text is Rich Text? I need this for an application that will center unformatted text but display Rich Text as given.

    I'm hoping that "Qt::mightBeRichText()": has been secretly exposed to QML and that I've simply missed it in the Fine Manual. :-)

  • For QtQuick 1.x, the Text element internally uses Qt::mightBeRichText() when textFormat is set to Text.AutoText (which is the default). Does this work for your case, or do you need something more?

  • I need something more. I am looking for a way to detect Rich Text myself so that I can apply additional formatting, such as setting horizontalAlignment, to plain text. It is not sufficient to use Text.AutoText.

    Can call Qt::mightBeRichText() from my QML application?

  • Qt::mightBeRichText() isn't available from QML out-of-the-box -- you'd need to expose it from C++ yourself, or write similar functionality in JS.

  • That's what I feared. Thanks, mbrasser.

  • Hi,

    you can use onTextChanged signal in Text element to parse for HTML tags or something like this.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.