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. QLabel with wordWrap, fixed vertical policy and stretched for the whole QDialog's width fails to resize height
Forum Updated to NodeBB v4.3 + New Features

QLabel with wordWrap, fixed vertical policy and stretched for the whole QDialog's width fails to resize height

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 3.3k Views 1 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.
  • Kelly RyanK Offline
    Kelly RyanK Offline
    Kelly Ryan
    wrote on last edited by Kelly Ryan
    #1
    1. Created a new project with QDialog as base class.
    2. Put QLabel on it.
    3. Added vertical layout to QDialog.
    4. Set Vertical Policy=Fixed and wordWrap=true for QLabel.
    5. Typed some text.

    3fae5e1e-524a-4ce4-a63c-9d645dcec630-image.png

    Seems like a bug to me because this behavior doesn't make any sense for such a trivial task as this one.

    Or am I wrong?

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

      Hi
      But did you set a fixed size to the QLabel ? maximum width.
      It seems to take all space it can get?

      1 Reply Last reply
      0
      • Kelly RyanK Offline
        Kelly RyanK Offline
        Kelly Ryan
        wrote on last edited by Kelly Ryan
        #3

        But did you set a fixed size to the QLabel ?

        QLabel
        Horizontal Policy=Preferred
        Vertical Policy=Fixed

        maximum width.

        Why would I want to set maximum width if I want it to be stretched for whole QDialog's width? And being able to resize the width along with QDialog.

        It seems to take all space it can get?

        Yeah, it gets all the horizontal space even after resizing QDialog.

        P.s. it's annoying to wait 10 minutes for being able to reply back, lol.

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

          Hi
          But in the picture, there is still space left so and hence it won't word wrap. (yet)

          So im not sure I understand what is wrong then.

          • P.s. it's annoying to wait 10 minutes for being able to reply back, lol.
            Yes. Its spam prevention but yeah...
          1 Reply Last reply
          0
          • Kelly RyanK Offline
            Kelly RyanK Offline
            Kelly Ryan
            wrote on last edited by Kelly Ryan
            #5

            But in the picture, there is still space left so and hence it won't word wrap. (yet)

            That's the point. You just said how it was supposed to work. It shouldn't have done word wrapping since it didn't even hit the end and as you said there is still space left.

            But in fact it does word wrapping.

            No word wrapping:
            4c7c3cd5-fc9e-419b-8771-e95d8d4642d7-image.png
            Now it decides to make a new line (notice how height has changed):
            0472fa41-58a6-429e-b082-0db99afe91a3-image.png
            Another new line:
            21c0f47d-cbfc-4330-80b1-16e1d5027fb0-image.png
            And another one:
            ce7a2441-0311-4080-9f57-a5ee6069dbc3-image.png

            mrjjM 1 Reply Last reply
            1
            • Kelly RyanK Kelly Ryan

              But in the picture, there is still space left so and hence it won't word wrap. (yet)

              That's the point. You just said how it was supposed to work. It shouldn't have done word wrapping since it didn't even hit the end and as you said there is still space left.

              But in fact it does word wrapping.

              No word wrapping:
              4c7c3cd5-fc9e-419b-8771-e95d8d4642d7-image.png
              Now it decides to make a new line (notice how height has changed):
              0472fa41-58a6-429e-b082-0db99afe91a3-image.png
              Another new line:
              21c0f47d-cbfc-4330-80b1-16e1d5027fb0-image.png
              And another one:
              ce7a2441-0311-4080-9f57-a5ee6069dbc3-image.png

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

              @Kelly-Ryan
              Hi
              It seems to work as expected here Qt 5.15
              I followed your steps and I colored the Label green to be able to see its bounds.

              alt text

              What Qt version are you seeing this ?

              1 Reply Last reply
              0
              • Kelly RyanK Offline
                Kelly RyanK Offline
                Kelly Ryan
                wrote on last edited by
                #7

                Oh, well, it's probably the case. I'm currently on 5.12.10. x)
                I'm gonna try a bit later with updated version.

                1 Reply Last reply
                0
                • Kelly RyanK Offline
                  Kelly RyanK Offline
                  Kelly Ryan
                  wrote on last edited by Kelly Ryan
                  #8

                  I've downloaded 6.1.2 and it's the same.
                  Your label is not in QDialog but QMainWindow, I assume, 'cause of "Type Here" in the top left corner.

                  Try to put a label in QDialog (even better if recreating step by step that I wrote in the first message) or if you want you can download my project:
                  https://mega.nz/file/91FlQapZ#TvAc0SAahkPxBRr_g3MJSo-Z3-dTMCKgwqh9EHB9rqg

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

                    Hi
                    +1 for runnable project.

                    Ah I think i missed the point that the odd thing happens while typing. not so much just running it with some text.

                    alt text

                    I agree that looks a bit buggy as why should it increase in size while typing.

                    I think it comes from its sizeHint

                    QSize QLabel::sizeHint() const
                    {
                        Q_D(const QLabel);
                        if (!d->valid_hints)
                            (void) QLabel::minimumSizeHint();
                        return d->sh;
                    }
                    

                    minimumSizeHint calls this
                    https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qlabel.cpp.html#_ZNK13QLabelPrivate12sizeForWidthEi

                    there it tries to find the longest word to use for word-break and I agree its a bit odd how it reacts while typing as those extra spaces
                    are not needed.

                    So yes the calc seems a bit off.

                    1 Reply Last reply
                    1

                    • Login

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