java拖拽排序_如何重新排序QML Row的子项(使用拖放)?

比方说,我有一个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中做到这一点,还是我运气不好?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值