Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How to manually wrap a plain QStaticText?

    General and Desktop
    2
    5
    2768
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Asperamanca last edited by

      Hi,

      I am using QStaticText quite a lot, both for single line and multi-line texts. Only plain text is required, so I stick with that.

      One question remains a mystery to me: How do I manually, explicitly wrap a plain text at a certain position within the text?

      E.g. when I provide the following text:

      The text should break\nright here

      I would like it to output:

      The text should break
      right here

      How do I achieve this?

      1 Reply Last reply Reply Quote 0
      • F
        fluca1978 last edited by

        It seems that you can format your text as HTML code fragment and force a break where you want:

        bq. 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.

        1 Reply Last reply Reply Quote 0
        • A
          Asperamanca last edited by

          For everything else BUT line breaks, I want plain text.

          How would I ensure that the string (which comes from an XML file) is plain text?

          BTW, this is running on epically slow hardware. Will using HTML not completely kill my performance?

          1 Reply Last reply Reply Quote 0
          • F
            fluca1978 last edited by

            [quote author="Asperamanca" date="1322473872"]
            How would I ensure that the string (which comes from an XML file) is plain text?
            [/quote]

            I don't know about any particular library that can unsescape XML/HTML strings. If your input is good enough you can manually remove unwanted tags, but this is not very elegant....

            1 Reply Last reply Reply Quote 0
            • A
              Asperamanca last edited by

              Sounds like a manual wrap is not intended for plain text.

              I have to say, QTextOption::ManualWrap raised some expectations, although the documentation does say "Same as QTextOption::NoWrap"

              I don't really get it, I have to admit. Why make a separate enum value that, from it's name, suggests a different behaviour, then say "it's the same as a different enum value".

              1 Reply Last reply Reply Quote 0
              • First post
                Last post