QML:如何动态添加Row

时间:2014-10-16 18:21:43

标签: qt qml

我有一个简单的qml文件,可以创建我的qml组件,如下所示。我需要在control_section中加载不同的控件组件。

以下是我需要支持的不同控制案例

  • 单个按钮
  • 两个带水平布局的按钮(行)
  • 两个文本框和一个垂直布局的按钮(行)

第一种情况只需一个按钮即可。但是在第二种情况下只显示最后一个按钮。如何在行中显示两个按钮?

注意 :问题似乎是按钮相互重叠

Frame.qml

Item {
    id: frame
    width: 400
    height: 500
    property alias components: control_section.sourceComponent
    Loader  {...}
    Image {...}
    Text {...}
    Loader{
        id: control_section
        ...
    }
}

OtherButton.qml

Item { ..; Button {...};}

main.qml

Frame {
    components: Row {
        OtherButton {}
        OtherButton {}
    }
}

1 个答案:

答案 0 :(得分:0)

我使用ListView解决了这个问题。这样按钮显示正确。

ListModel {
    id: listModel
    ListElement {text: "A"; next: "first.qml"}
    ListElement {text: "B"; next: "second.qml"}
}

Component {
    id: listDelegate
    Item {
       OtherButton  {}
    }
}

ListView {
    model : listModel
    delegate: listDelegate
}
相关问题