Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QLabel with wordwrap only fills half of available horizontal space

    General and Desktop
    3
    4
    1202
    Loading More Posts
    • 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.
    • S
      SeanOCR last edited by

      I've run into this problem on a couple of occasions and I'm starting to think it's a QT bug but want to post before coming to that conclusion. My issue is that when I enable word wrap on a label, it only goes half way across the available horizontal space before going to the next line. I think that QStackWidget may have something to do with it as it has been involved in every instance that I've seen this occur.

      My setup is very simple, it's a QStackWidget that holds a number of widgets, but for this example it currently only holds one QVBoxLayout with a QLabel and a button. The annoying thing is I know it knows there is more space because if I center the label it goes right in the middle where you would expect it too, but still is only half the size it should be. My current work around is to setMinimumWidth with double it's current size. I've attached a picture to help illustrate the issue.

      I've tried every combination of SizePolicy you can imagine, but it doesn't make a difference. I've also tried other layouts and it seems to effect all of them. Oddly, when I use QHBoxLayout the label will take up the first half of the the first row and the button will take up the 2nd half, but the text still only fills half the label.

      !http://thecandlelightcoder.com/BadLabels.png(Picture showing bad label word wrap)!

      1 Reply Last reply Reply Quote 0
      • B
        Binary91 last edited by

        I don't know if that fixes your problem, but you can try to change the QLabel's sizePolicy.
        When using QLabels in a QLayout, the QLabels inherit the QLayout's sizePolicy, so maybe you have to set sizePolicy to QSizePolicy::Maximum or something like that... Try it and tell me if it works :-)

        1 Reply Last reply Reply Quote 0
        • S
          SeanOCR last edited by

          Thank you for the reply Binary91, but I've tried every combination of SizePolicy you can imagine with no luck :/

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi and welcome to devnet,

            Can you show the code you use to setup your widgets ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • First post
              Last post