What is the difference between Row and RowLayout?

情到浓时终转凉″ 提交于 2020-01-12 06:58:11

问题


This works as intended with Row, but not with RowLayout. Why? What is the difference between the two?

ApplicationWindow {    
    title: "Testing"
    width: 640
    height: 480

    //RowLayout {
    Row {        
        anchors.fill: parent

        Rectangle {
            id: rect1
            width: parent.width * 0.3
            height: parent.height
            color: "blue"
        }
        Rectangle {
            height: parent.height
            width: parent.width * 0.7
            color: "red"
        }
    }
}

回答1:


Row is a Item Positioner. Positioner items are container items that manage the positions of items in a declarative user interface.

RowLayout is part of Qt Quick Layouts. They manage both the positions and the sizes of items on a declarative user interface, and are well suited for resizable user interfaces.

Your code with RowLayout should look like this:

RowLayout{
    anchors.fill: parent
    spacing: 0
    Rectangle{
        Layout.fillHeight: true
        Layout.preferredWidth: parent.width * 0.3
        color: "blue"
    }
    Rectangle{
        Layout.fillHeight: true
        Layout.fillWidth: true
        color: "red"
    }
}


来源:https://stackoverflow.com/questions/29482970/what-is-the-difference-between-row-and-rowlayout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!