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 does textWidth work exactly?
QtWS25 Last Chance

How does textWidth work exactly?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 456 Views
  • 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.
  • T Offline
    T Offline
    Tink
    wrote on 17 Mar 2022, 14:38 last edited by Tink
    #1

    Hi, I'm trying to understand why QTextDocument setTextWidth doesn't give me the results i want. I want a maximum width all the time (using a QTextEdit and QTextBrowser). However now i just get the correct width some of the time and i can't figure out why it fails.

    The documentation https://doc.qt.io/qt-6/qtextdocument.html#textWidth-prop mentions that if the text cannot be broken into multiple lines to fit into the specified text width it will be larger. So i assume that is what is happening... but why... Also on text that does fit correctly it changes to the maximum width, of the widget, after a window resize.

    The following however almost does exactly what i want, change the widgets lineWrapMode from WidgetWidth to FixedWidgetWidth and set setLineWrapColumnOrWidth(). However now the text will not resize if the window becomes smaller than the specified size .

    M 1 Reply Last reply 17 Mar 2022, 15:38
    0
    • T Tink
      17 Mar 2022, 14:38

      Hi, I'm trying to understand why QTextDocument setTextWidth doesn't give me the results i want. I want a maximum width all the time (using a QTextEdit and QTextBrowser). However now i just get the correct width some of the time and i can't figure out why it fails.

      The documentation https://doc.qt.io/qt-6/qtextdocument.html#textWidth-prop mentions that if the text cannot be broken into multiple lines to fit into the specified text width it will be larger. So i assume that is what is happening... but why... Also on text that does fit correctly it changes to the maximum width, of the widget, after a window resize.

      The following however almost does exactly what i want, change the widgets lineWrapMode from WidgetWidth to FixedWidgetWidth and set setLineWrapColumnOrWidth(). However now the text will not resize if the window becomes smaller than the specified size .

      M Offline
      M Offline
      mpergand
      wrote on 17 Mar 2022, 15:38 last edited by
      #2

      @Tink
      Hi,

      Is your TextView inserted in a layout ?
      As far as I know, you only need to set the textWidth if you use QTextDocument alone and call drawContents() yourself.

      T 1 Reply Last reply 17 Mar 2022, 15:59
      0
      • M mpergand
        17 Mar 2022, 15:38

        @Tink
        Hi,

        Is your TextView inserted in a layout ?
        As far as I know, you only need to set the textWidth if you use QTextDocument alone and call drawContents() yourself.

        T Offline
        T Offline
        Tink
        wrote on 17 Mar 2022, 15:59 last edited by Tink
        #3

        @mpergand i'm trying to get the text to wrap after a certain width has been reached. Everything has a layout.

        1 Reply Last reply
        0

        2/3

        17 Mar 2022, 15:38

        • Login

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