[Solved] QTextDocument: adjustSize ignoring setTextWidth
-
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? -
The trick is not to use adjustSize(). Instead, just set the desired text width, and query the size().
-
Thanks for sharing your experience.
-
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.