Row和RowLayout有什么区别?

Pat*_*ric 12 qt qml qtquick2

这可以按预期使用Row,但不能使用RowLayout.为什么?两者有什么区别?

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"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Mee*_*fte 21

Row物品定位器.定位器项是管理声明性用户界面中项的位置的容器项.

RowLayoutQt Quick Layouts的一部分.它们在声明性用户界面上管理项目的位置和大小,非常适合可调整大小的用户界面.

您的代码RowLayout应如下所示:

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"
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 虽然这是唯一的答案,但我认为这不是一个有用的答案。它只是复制文档,这可以说没有任何作用来揭开差异的神秘面纱,因此这个问题。“Row”是一个“项目定位器”。所以呢?`RowLayout` 是 QT 快速布局的一部分。好吧,“Row”也是 QTQuick 的一部分。概念和用途上的实际和根本差异是什么?!?! (10认同)
  • 作为对 Meefte 的补充回答。Row 是 [Item Positioners](https://doc.qt.io/qt-5/qtquick-positioning-layouts.html),RowLayout 是 [Qt Quick Layouts](https://doc.qt.io/qt- 5/qtquicklayouts-index.html)。它们的行为方式相似,但有两个不同之处: - 物品定位器本身也是容器。- Qt 快速布局可以调整其项目的大小。 (2认同)