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. [Solved]RowLayout doesn't support dynamic item insertion?
Forum Updated to NodeBB v4.3 + New Features

[Solved]RowLayout doesn't support dynamic item insertion?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.4k 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.
  • V Offline
    V Offline
    Vincent007
    wrote on last edited by
    #1

    RowLayout does not support dynamic item insertion?
    I expect two rectangles can been seen inside RowLayout. RowLayout works fine when two rectangles are created statically. However, RowLayout doesn't work properly when two rectangles are created dynamically. Two rectangles are overlapped.

    static approach
    @import QtQuick 2.0
    import QtQuick.Controls 1.0
    import QtQuick.Layouts 1.0

    Rectangle {
    height: 640
    width: 2*640 + 40

    RowLayout {
        id: rowLayout
        anchors.fill: parent
        spacing: 10
        Rectangle {
            height: parent.height
            width: parent.height
            color: "red"
        }
    
        Rectangle {
            height: parent.height
            width: parent.height
            color: "blue"
        }
    }
    

    }@

    dynamic approach
    @import QtQuick 2.0
    import QtQuick.Controls 1.0
    import QtQuick.Layouts 1.0

    Rectangle {
    height: 640
    width: 2*640 + 40
    Component {
    id: rect
    Rectangle {
    height: parent.height
    width: parent.height
    }
    }

    RowLayout {
        id: rowLayout
        anchors.fill: parent
        spacing: 10
    }
    
    Component.onCompleted: {
        rect.createObject(rowLayout,{"color":"red"});
        rect.createObject(rowLayout,{"color":"blue"});
    }
    

    }@

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      The real issue here is actually that you don't provide an implicit size for the rectangles. The problem with assigning width in a layout is that that information is useless when you start resizing it. Keep in mind that layouts by definition change the size of your item.

      To make this work, simply change your rectangles to set implicitWidth and implicitHeight instead as that information is retained even after your layout is resized.

      1 Reply Last reply
      1
      • V Offline
        V Offline
        Vincent007
        wrote on last edited by
        #3

        Thank Jens

        RowLayout works fine after I set implicitWidth and implicitHeight

        @ Component {
        id: rect
        Rectangle {
        implicitWidth: parent.height
        implicitHeight: parent.height
        }
        }@

        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