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. Behavior that i cant explain between RowLayout and custom RowLayout nested in Rectangle
Forum Updated to NodeBB v4.3 + New Features

Behavior that i cant explain between RowLayout and custom RowLayout nested in Rectangle

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 179 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.
  • S Offline
    S Offline
    saltyFlow
    wrote on last edited by
    #1

    Hello everybody,

    I am fairly new to Qt and QML so i hope my question won't be too stupid. Sorry if it's the case.

    While playing with Layouts ( I tried to encapsulate Row/Column Layouts into components to add "visual debugging" borders basically), I encounter a behavior that i can't explain.

    60b62e7e-884e-4198-8808-4264523d1ceb-image.png

    Can someone provide some explanation please on why on the left the 3 items inside a RowLayout are stacked to the left? While on the right (custom RowLAyout nested inside a rectangle) it's evenly spaced of course

    I would expect the left behavior to be the same as right

    Thank you

    My code:

    // main.qml
    import QtQuick
    import QtQuick.Window
    import QtQuick.Controls
    import QtQuick.Layouts
    
    Window {
        id: root
        width: 800
        height: 600
        visible: true
    
    
        RowLayout {
            id: rl1
            anchors.fill :parent
    
            Rectangle {
                color: "transparent"
                border.color: "orange"
                Layout.fillHeight: true
                Layout.fillWidth: true
                ColumnLayout {
    
                    anchors.fill: parent
    
                    RowLayout {
                        Layout.fillWidth: true
                        Layout.preferredHeight: implicitHeight
    
                        Text {
                            text: "item3.1"
                            // Layout.fillHeight:true // Need to be commented else whole colomn is taken..
                            Layout.preferredWidth: implicitWidth
                            DebugRectangle {}
                        }
                        Text {
                            text: "item3.2"
                            // Layout.fillHeight:true
                            Layout.preferredWidth: implicitWidth
                            DebugRectangle {}
                        }
                        Text {
                            text: "item3.3"
                            // Layout.fillHeight:true
                            Layout.preferredWidth: implicitWidth
                            DebugRectangle {}
                        }
    
                    }
    
    
                }
            }
    
    
            MyColumnLayout {
                Layout.fillHeight: true
                Layout.fillWidth: true
    
                MyRowLayout {
                    Layout.fillWidth: true
                    Layout.preferredHeight: implicitHeight
    
                    Text {
                        text: "item3.1"
                        Layout.fillHeight:true
                        Layout.preferredWidth: implicitWidth
                        DebugRectangle {}
                    }
                    Text {
                        text: "item3.2"
                        Layout.fillHeight:true
                        Layout.preferredWidth: implicitWidth
                        DebugRectangle {}
                    }
                    Text {
                        text: "item3.3"
                        Layout.fillHeight:true
                        Layout.preferredWidth: implicitWidth
                        DebugRectangle {}
                    }
                    // Rectangle { // spacer. Uncomment to achieve "left behavior"
                    //     border.color: "blue"
                    //     Layout.fillWidth: true
                    //     Layout.fillHeight: true
                    // }
    
                }
            }
    
    
        }
    
    
    
    
    
    }
    
    //DebugRectangle
    import QtQuick
    
    Rectangle {
        property var toFill: parent
        property color borderColor: "blue"
        property int borderWidth: 1
    
        anchors.fill: toFill
        z: 200
        color: "transparent"
        border.color: borderColor
        border.width: borderWidth
    }
    
    // MyColumnLayout.qml
    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Layouts 1.15
    
    Rectangle {
        id: root
    
        default property alias data: layout.data
        property alias myspacing: layout.spacing
        property color borderColor: "green"
    
    
        color: "transparent"
        border.color: borderColor
        radius: 2
        border.width: 2
    
    
        ColumnLayout {
            id: layout
            anchors.fill: parent
    
            // Set implicitWidth based on the widest child in the layout
            // implicitWidth: childrenRect.width
        }
    }
    
    
    // MyRowLayout.qml
    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Layouts 1.15
    
    Rectangle {
        id: root
    
        default property alias data: layout.data
        property alias myspacing: layout.spacing
        property color borderColor: "cyan"
    
        color: "transparent"
        border.color: borderColor
        radius: 2
        border.width: 2
    
        // Calculate implicitHeight based on the tallest child in the RowLayout
        implicitHeight: layout.implicitHeight
    
        RowLayout {
            id: layout
            anchors.fill: parent
            // anchors.margins: 10 // Default margin if no property overwrite
    
            // Set implicitHeight based on the tallest child in the layout
            implicitHeight: childrenRect.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