比方说,我有一个QML Row ,它有一些子对象(不一定是同一类型) . 我希望能够随意重新排序 . 奖金是,能够为用户实现拖放行为 . 这是一个代码示例, Row 具有不同的组件,我想重新排序:
import QtQuick 2.5
import QtQuick.Controls 1.4
ApplicationWindow {
visible: true
width: 300
height: 300
Component {
id: rect
Rectangle {
color: "blue"
}
}
Component {
id: rectWithText
Rectangle {
property alias text: txt.text
color: "red"
Text {
id: txt
}
}
}
Row {
id: r
Component.onCompleted: {
rect.createObject(r,{"width": 60,"height":40})
rectWithText.createObject(r,{"width": 100,"height":40,text:"foo"})
rect.createObject(r,{"width": 40,"height":40})
}
}
}
在QtWidgets中,有一些函数,如 layout->removeWidget(widget) , layout->insertWidget(index,widget) 等,但它们似乎在QML中缺失 .
我发现了一些使用 ListView / GridView 和模型/委托方法的示例,但它们通常无法处理不同的组件,因此它们不能真正替代 Row .
有没有办法在QML中做到这一点,还是我运气不好?