Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Using ColumnLayout breaks Label wrap/resize
Forum Updated to NodeBB v4.3 + New Features

Using ColumnLayout breaks Label wrap/resize

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 1.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.
  • M Offline
    M Offline
    mzimmers
    wrote on 31 Mar 2021, 23:12 last edited by mzimmers 4 Jan 2021, 15:29
    #1

    Hi all -

    Working with a QML view that goes like this:

    ColumnLayout {
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.fill: parent
    
        Label { id: heading ... }
        Label {
          id: subHeading
          Layout.alignment: Qt.AlignHCenter
          text: changeConsumablesViewModel.posterModalSubHeading;
          font: Theme.plateLabelLargeFont;
        //          fontSizeMode: Text.Fit;
        //          minimumPixelSize: 10;
        //          font.pixelSize: 72;
          color: Theme.neutralLightest
          wrapMode: Text.Wrap
        }
        Column { id: checklist }
        ...
    

    Which produces this:

    nowrap.PNG

    Everything is supposed to be centered, and in fact is centered if the text doesn't exceed a certain (currently unknown to me) length. My attempts to wrap (and I included a width) didn't work, so I tried the fontSizeMode setting (shown in the commented code above), and got this disaster:

    wrong.PNG

    Can someone tell me why this isn't resizing the subheading to fit in the window? Thanks...

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VStevenP
      wrote on 1 Apr 2021, 01:12 last edited by
      #2

      Please see the documentation for WrapMode for Text and Label.

      Here's an excerpt:

      wrapMode : enumeration
      Set this property to wrap the text to the Text item's width. The text will only wrap if an explicit width has been set. wrapMode can be one of:

      M 1 Reply Last reply 1 Apr 2021, 14:36
      0
      • V VStevenP
        1 Apr 2021, 01:12

        Please see the documentation for WrapMode for Text and Label.

        Here's an excerpt:

        wrapMode : enumeration
        Set this property to wrap the text to the Text item's width. The text will only wrap if an explicit width has been set. wrapMode can be one of:

        M Offline
        M Offline
        mzimmers
        wrote on 1 Apr 2021, 14:36 last edited by
        #3

        @VStevenP as mentioned above, I did include a width setting when I tried wrapping. I just tried it again. Here's the code:

        Label {
          Layout.alignment: Qt.AlignHCenter
          text: changeConsumablesViewModel.posterModalSubHeading;
          font.pointSize: 36.0
          width: 640
          wrapMode: Text.Wrap
        }
        

        And here's the result:
        wrong.PNG

        So, something else I'm doing (or not doing) is interfering with the wrapping.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mzimmers
          wrote on 1 Apr 2021, 15:28 last edited by mzimmers 4 Jan 2021, 16:12
          #4

          Update: by process of elimination, I traced the cause to my use of ColumnLayout. Changing topic title accordingly.

          EDIT: So, it appears that the missing ingredient was a Layout.preferredWidth:

          Label {
              Layout.alignment: Qt.AlignHCenter
              text: changeConsumablesViewModel.posterModalSubHeading
              width: parent.width * 0.9
              Layout.preferredWidth: width
              fontSizeMode: Text.Fit
              minimumPixelSize: 18
              font.pixelSize: Theme.plateLabelLargeFont.pixelSize
              wrapMode: Text.Wrap
            }
          

          produces this:

          right.PNG

          I didn't realize that I needed to apply Layout properties to the individual elements of a Layout; but evidently I did.

          1 Reply Last reply
          2

          1/4

          31 Mar 2021, 23:12

          • Login

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