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 only fills half of available horizontal space

QLabel with wordwrap only fills half of available horizontal space

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.8k 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.
  • S Offline
    S Offline
    SeanOCR
    wrote on last edited by
    #1

    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
    0
    • B Offline
      B Offline
      Binary91
      wrote on last edited by
      #2

      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
      0
      • S Offline
        S Offline
        SeanOCR
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0

          • Login

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