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?
Forum Updated to NodeBB v4.3 + New Features

How does textWidth work exactly?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 515 Views 2 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.
  • T Offline
    T Offline
    Tink
    wrote on 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
    0
    • T Tink

      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 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
      0
      • M mpergand

        @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 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

        • Login

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