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. [Solved] QTextDocument: adjustSize ignoring setTextWidth
Forum Updated to NodeBB v4.3 + New Features

[Solved] QTextDocument: adjustSize ignoring setTextWidth

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.1k 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

    I try to evaluate a reasonable size for a text using a QTextDocument.

    @
    m_pLayoutTextDocument->setPlainText(plainText);
    m_pLayoutTextDocument->setDefaultFont(usedFont);
    m_pLayoutTextDocument->setDefaultTextOption(textOption);
    m_pLayoutTextDocument->setTextWidth(desiredTextWidth);

    m_pLayoutTextDocument->adjustSize();@

    Text, Font and TextOption are all constant for my current test case. Only the desiredTextWidth changes with subsequent calls.

    Nevertheless, for any text width, I always receive a 'reasonable size' of 195, 48.

    My QTextDocument has been created using the default constructor. Other than the lines quoted above, no properties have been changed.
    The text option specified includes the "WordWrap" option. The text itself is "Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj", i.e. very wrapping-friendly. With reduced width, I actually expected the reasonable size to decrease in width and expand in height.

    I have also tried debugging into QTextDocument.adjustSize(), but couldn't make much sense of it.

    Ideas?

    EDIT:
    Do I have to tell QTextDocument somehow to rewrap the text according to the textWidth?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      The trick is not to use adjustSize(). Instead, just set the desired text width, and query the size().

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

        Thanks for sharing your experience.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Asperamanca
          wrote on last edited by
          #4

          Welcome!

          I have found it to be good practice to answer even to my own threads. More than once, years later, I stumbled upon my own questions again, and was always happy to find an answer there - be it by someone else, or myself.

          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