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. Resize children based on number
Forum Updated to NodeBB v4.3 + New Features

Resize children based on number

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 346 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.
  • A Offline
    A Offline
    aconnell
    wrote on last edited by
    #1

    How would I update the size of children in a layout (using GridLayout now but not required) so the children evenly take up the space of the parent. I have an app where users can add charts to a page and I'd like them to resize when they are added/removed. I've seen this example on stack overflow, which gets me mostly there, but the size of the children is fixed, I'd like them to resize with the window, like in the pics below Layout1.png
    Layout2.png
    Layout3.png

    KroMignonK 1 Reply Last reply
    0
    • A aconnell

      How would I update the size of children in a layout (using GridLayout now but not required) so the children evenly take up the space of the parent. I have an app where users can add charts to a page and I'd like them to resize when they are added/removed. I've seen this example on stack overflow, which gets me mostly there, but the size of the children is fixed, I'd like them to resize with the window, like in the pics below Layout1.png
      Layout2.png
      Layout3.png

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by KroMignon
      #2

      @aconnell said in Resize children based on number:

      How would I update the size of children in a layout (using GridLayout now but not required) so the children evenly take up the space of the parent.

      With GridLayout or ColumnLayout you could use Layout.fillHeight:

      ColumnLayout  {
          Rectangle {
              Layout.fillWidth: true;
              Layout.fillHeight: true;
              color: "blue"
          }
          Rectangle {
              Layout.fillWidth: true;
              Layout.fillHeight: true;
              color: "green"
          }
          Rectangle {
              Layout.fillWidth: true;
              Layout.fillHeight: true;
              color: "yellow"
          }
      }
      

      ==> all 3 rectangles will have same height

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      1
      • A Offline
        A Offline
        aconnell
        wrote on last edited by
        #3

        KroMignon - thanks for the response, but I don't always want them to be evenly sized. I have this now, as you suggested.

                GridLayout {
                    id: gridLayout
                    columns: 1
                    anchors.left: parent.left
                    anchors.right: parent.right
                    anchors.top: reset.bottom
                    anchors.bottom: parent.bottom
        
                    Loader {
                        id: chartLoaderOne
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                    }
                    Loader {
                            id: chartLoaderTwo
                            Layout.fillWidth: true
                            Layout.fillHeight: true
                    }
                    Loader {
                        id: chartLoaderThree
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                    }
                }
        

        The loaders are always 1/3 of the total space. What I'd like it to do is when one chart is added, the whole space of the GridLayout is filled with the one chart. When two added, the charts fill the space 50/50. When three added, they fill 1/3 each. What I'd like to do is something like this - which doesn't work......

        GridLayout {
                    id: gridLayout
                    columns: 1
                    anchors.left: parent.left
                    anchors.right: parent.right
                    anchors.top: reset.bottom
                    anchors.bottom: parent.bottom
                    Loader {
                        id: chartLoaderOne
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                        Layout.minimumHeight: gridLayout.height/3
                        Layout.maximumHeight: gridLayout.height
                    }
                    Loader {
                            id: chartLoaderTwo
                            Layout.fillWidth: true
                            Layout.fillHeight: true
                            Layout.minimumHeight: 0
                            Layout.maximumHeight: gridLayout.height/2
                    }
                    Loader {
                        id: chartLoaderThree
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                        Layout.minimumHeight: 0
                        Layout.maximumHeight: gridLayout.height/3
                    }
                }
        
        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          Do Layout.minimumHeight on all at 1/3 of parent height (or a fraction based upon number of charts). Then set the active or larger chart to Layout.fillHeight: true. This should enlarge that one to fill the space. This should allow you to use a model with a Repeater or ListView to make it automatically adjust to the number of charts too. You would just have to have a way to identify which chart is the active chart.

          C++ is a perfectly valid school of magic.

          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