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 Updated to NodeBB v4.3 + New Features

Why parent.height doesn't work

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 4 Posters 929 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 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 last edited by z3dd
      #2

      Try this:

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

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

      GrecKoG 1 Reply Last reply
      1
      • Z z3dd

        Try this:

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

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

        GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on 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
        1
        • GrecKoG GrecKo

          @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 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 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

            • Login

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