Nominate our 2022 Qt Champions!

How to make QTextLayout don't ignore 0x20(whitespace)

  • Hello guys,
    When I use QTextLayout to layout a multiline texts,if the QTextLine include 0x20 on the head or tail,QTextLayout will ignore and the QTextLine's width will less than tha actual width.
    How can I to fix it?
    My one solution is to replace 0x20 to 0xa0,but this will cause WordWrap don't work

  • First, the docs say that QTextLayout is a low-level class and not normally used. Then, what happens if you change your text to a fixed space font? You need to elaborate on what you mean by "width less than actual width". Does the character count of the QString in the layout not reflect the spaces, or are you just visually not seeing the text occupying the expected screen realestate?

  • I'm should use QTextLayout to achieve custom needs.when I set multi-lines text to QTextLayout ,if paragraph which have 0x20(white space) or \n,these whitespace words will be ignored and I need layout to calculate these words.

Log in to reply