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 margins combined with layouts
QtWS25 Last Chance

Using margins combined with layouts

Scheduled Pinned Locked Moved QML and Qt Quick
layoutmargins
4 Posts 2 Posters 1.8k Views
  • 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.
  • Q Offline
    Q Offline
    qwasder85
    wrote on 13 Mar 2015, 09:47 last edited by
    #1

    Hey all,
    I have a UI that features Layouts nested in Layouts (i.e. a RowLayout somewhere within a ColumnLayout, filling width and height).
    It would be great if I could use margins alongside, but it doesn't seem to have any effect if I don't use anchors to place the elements.
    Is there a little workaround for that or do I have to choose one technique?

    Following is a little example. How would I go about setting margins for one of the nested Layouts in there?

    ColumnLayout
    {
        anchors.fill: parent
    
        spacing: 0
    
        Rectangle
        {
            Layout.fillWidth: true
    
            color: "darkblue"
            height: 35
        }
    
        RowLayout
        {
            Layout.fillWidth: true
            Layout.fillHeight: true
    
            spacing: 5
    
            ColumnLayout
            {
                id: centerLeftColumnLayout
    
                Layout.fillWidth: true
                Layout.fillHeight: true
    
                Rectangle
                {
                    Layout.fillWidth: true
    
                    color: "yellowgreen"
                    height: 30
                }
    
                Rectangle
                {
                    id: signalTiles
    
                    Layout.fillWidth: true
                    Layout.fillHeight: true
    
                    color: "lightblue"
                }
    
                Rectangle
                {
                    Layout.fillWidth: true
    
                    color: "green"
                    height: 50
                }
            }
    
            ColumnLayout
            {
                Layout.fillWidth: true
                Layout.fillHeight: true
    
                spacing: 0
    
                Rectangle
                {
                    Layout.fillWidth: true
    
                    color: "red"
                    height: 30
                }
    
                Rectangle
                {
                    Layout.fillWidth: true
                    Layout.fillHeight: true
    
                    color: "blue"
                }
            }
        }
    
        Rectangle
        {
            Layout.fillWidth: true
    
            color: "orange"
            height: 40
        }
    }
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      Manfred
      wrote on 13 Mar 2015, 10:02 last edited by
      #2

      Hi,

      I solved this kind of problem by wrapping the items to be laid out into rectangles.
      This way you can use the anchors margin properties inside the rectangle as you wish and the layout is done for the rectangles.

      Hope this helps!
      cheers,
      Manfred

      Q 1 Reply Last reply 13 Mar 2015, 10:45
      0
      • M Manfred
        13 Mar 2015, 10:02

        Hi,

        I solved this kind of problem by wrapping the items to be laid out into rectangles.
        This way you can use the anchors margin properties inside the rectangle as you wish and the layout is done for the rectangles.

        Hope this helps!
        cheers,
        Manfred

        Q Offline
        Q Offline
        qwasder85
        wrote on 13 Mar 2015, 10:45 last edited by
        #3

        @Manfred That was my first intention, but it makes the code harder to read.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Manfred
          wrote on 13 Mar 2015, 10:49 last edited by
          #4

          You could put the content of the outer rectangles inside a component.
          This way the code would be hidden away in a separate qml file.

          cheers
          Manfred

          1 Reply Last reply
          0

          4/4

          13 Mar 2015, 10:49

          • Login

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