Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to manually wrap a plain QStaticText?
Forum Updated to NodeBB v4.3 + New Features

How to manually wrap a plain QStaticText?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.2k Views 1 Watching
  • 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 Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    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
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        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
        0
        • F Offline
          F Offline
          fluca1978
          wrote on last edited by
          #4

          [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
          0
          • A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            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
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved