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 can I prevent a wordWrapping QLabel from clipping on parent resize?
Forum Updated to NodeBB v4.3 + New Features

How can I prevent a wordWrapping QLabel from clipping on parent resize?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 3.0k 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.
  • l3u_L Offline
    l3u_L Offline
    l3u_
    wrote on last edited by l3u_
    #1

    Hi :-)

    I have a dialog displaying a QLabel with wordWrap set to true and a text spanning multiple lines. I also do setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum). The result on loading is:

    0_1562933719919_screenshot_1.png

    I can however make the dialog vertically smaller by some amount, and then, the text is clipped:

    0_1562933753803_screenshot_2.png

    How can I prevent this clipping? Thanks for all help!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      In what way prevent it ?
      It needs more space for full text so what should it do ?

      You can set a minimum size based on text size so it cant get too small.
      Or you can create a custom QLabel that can alter the font size so full text still fits to the
      new rect.

      https://stackoverflow.com/questions/42652738/how-to-automatically-increase-decrease-text-size-in-label-in-qt/42690033

      JonBJ 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        In what way prevent it ?
        It needs more space for full text so what should it do ?

        You can set a minimum size based on text size so it cant get too small.
        Or you can create a custom QLabel that can alter the font size so full text still fits to the
        new rect.

        https://stackoverflow.com/questions/42652738/how-to-automatically-increase-decrease-text-size-in-label-in-qt/42690033

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @mrjj
        I don't know, but I can only guess OP is claiming he does not have a maximum height on the multi-line label, yet he still sees clipping at the bottom. Which would make one think: this has nothing to do with wrapping, and he does have a max height somewhere he needs to track down?

        mrjjM 1 Reply Last reply
        1
        • JonBJ JonB

          @mrjj
          I don't know, but I can only guess OP is claiming he does not have a maximum height on the multi-line label, yet he still sees clipping at the bottom. Which would make one think: this has nothing to do with wrapping, and he does have a max height somewhere he needs to track down?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @JonB
          That could also be.
          Often poster wants the text to shrink :)

          1 Reply Last reply
          2
          • l3u_L Offline
            l3u_L Offline
            l3u_
            wrote on last edited by l3u_
            #5

            I don't understand why the label can be displayed so (vertically) small that the content is clipped, altough I set QSizePolicy::Minimum as the vertical size policy. I would like to ensure that the label can't be made smaller as it's content, so that no clipping can occur. And I thought Qt would take care of that it I set the correct size policy …

            I don't want the text size to change. Simply, the parent QDialog should reject to be dragged vertically smaller if the space to display all text is not sufficient anymore.

            According to teh docs, QSizePolicy::Minimum effects that the widget can't be smaller than it's sizeHint. So doesn't the label calculate it correctly? Shouldn't it be the size that it needed to display all text without clipping?

            JonBJ 1 Reply Last reply
            0
            • l3u_L l3u_

              I don't understand why the label can be displayed so (vertically) small that the content is clipped, altough I set QSizePolicy::Minimum as the vertical size policy. I would like to ensure that the label can't be made smaller as it's content, so that no clipping can occur. And I thought Qt would take care of that it I set the correct size policy …

              I don't want the text size to change. Simply, the parent QDialog should reject to be dragged vertically smaller if the space to display all text is not sufficient anymore.

              According to teh docs, QSizePolicy::Minimum effects that the widget can't be smaller than it's sizeHint. So doesn't the label calculate it correctly? Shouldn't it be the size that it needed to display all text without clipping?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @l3u_
              I believe your broad understating of the sizing is correct. Therefore I'm thinking that something is limiting the vertical size of your label. (Assuming Qt is not mis-measuring the height of your font/lines.) I don't think that the fact you are word wrapping should be the issue (e.g. comment out the wordWrap = true, does that make any difference?).

              If it were me, apart from looking for any maximum/fixed heights anywhere, I'd copy just what you need for this from your code into a little standalone project, and play with it there....

              1 Reply Last reply
              2
              • l3u_L Offline
                l3u_L Offline
                l3u_
                wrote on last edited by
                #7

                I played around with different size policies in my dialog. Maybe, this is caused somewhere else, the dialog I use is derived from a basic "dialog with a title label" class, which creates layouts, the derived class also adds layouts … seems to be a bit complicated ;-)

                Well, let's see …

                1 Reply Last reply
                1
                • l3u_L Offline
                  l3u_L Offline
                  l3u_
                  wrote on last edited by l3u_
                  #8

                  This thread is quite old, nevertheless, I stumbled upon it again with the very same problem.

                  I tried to reproduce this behavior with a minimal example to track it down. After all, I think I found the solution. It's not enough to set QSizePolicy::Minimum to the QLabels with the wordwrapped text. Widgets containing them (in the current case a QTabWidget) also have to be set to use QSizePolicy::Minimum vertically.

                  After having done that, I couldn't drag the dialog smaller than it should be and no clipping occured anymore. So the solution is to set the right QSizePolicy to the right widgets, which may cause some headache ;-)

                  1 Reply Last reply
                  3

                  • Login

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