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. Why parent.height doesn't work
Forum Update on Tuesday, May 27th 2025

Why parent.height doesn't work

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 4 Posters 928 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.
  • V Offline
    V Offline
    VincentLiu
    wrote on 6 Feb 2017, 03:20 last edited by
    #1

    Hi, I have a simple trouble about using parent information. I wonder under what scenarios does it works. Below is my code snippet:

    Page {
    
        id: mainPage
    
        height: Screen.desktopAvailableHeight - 55 - 30
        width: Screen.desktopAvailableHeight * 1.1
    
        ColumnLayout {
    
            anchors.fill: parent
            spacing: parent.height * 0.1    // DOESN'T WORK
    
            Text {
    
                text: qsTr("请选择下列一项功能:")
    
                font.pointSize: 16
    
                Layout.leftMargin: mainPage.width * 0.05     // DOESN'T WORK
            }
    
            ........
    }
    

    Both the "spacing: parent.height * 0.1" and "Layout.leftMargin: mainPage.width * 0.05" are 0 !! However, in the Qt Creator Design mode, both of them are correct.
    Can anyone give me some suggestions? Or actually I didn't use a recommended form to refer to parent information? Thanks

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      z3dd
      wrote on 6 Feb 2017, 09:36 last edited by z3dd 2 Jun 2017, 11:03
      #2

      Try this:

      spacing: Math.floor(parent.height * 0.1)
      

      Edit: Also, you probably should not specify anchor points for ColumnLayout.

      G 1 Reply Last reply 6 Feb 2017, 10:21
      1
      • Z z3dd
        6 Feb 2017, 09:36

        Try this:

        spacing: Math.floor(parent.height * 0.1)
        

        Edit: Also, you probably should not specify anchor points for ColumnLayout.

        G Offline
        G Offline
        GrecKo
        Qt Champions 2018
        wrote on 6 Feb 2017, 10:21 last edited by
        #3

        @z3dd said in Why parent.height doesn't work:

        Edit: Also, you probably should not specify anchor points for ColumnLayout.

        Why not ? That's the point of layouts, you specify a size and it will spread its children to fill it. If you don't want that, use a Column.

        Z 1 Reply Last reply 6 Feb 2017, 11:03
        1
        • G GrecKo
          6 Feb 2017, 10:21

          @z3dd said in Why parent.height doesn't work:

          Edit: Also, you probably should not specify anchor points for ColumnLayout.

          Why not ? That's the point of layouts, you specify a size and it will spread its children to fill it. If you don't want that, use a Column.

          Z Offline
          Z Offline
          z3dd
          wrote on 6 Feb 2017, 11:03 last edited by
          #4

          @GrecKo Oh yes, you right! I must have mixed up Column and ColumnLayout.

          1 Reply Last reply
          1
          • S Offline
            S Offline
            stcorp
            wrote on 6 Feb 2017, 13:49 last edited by
            #5

            Try using parent.implicitHeight. I've found that this sometimes works when height doesn't work as expected

            1 Reply Last reply
            1

            1/5

            6 Feb 2017, 03:20

            • Login

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