[英]best way to connect Drag&Drop to a function in a QListWidget
I have a QListWidget
filled with items. 我有一个装满物品的
QListWidget
。
The items' order is stored in a separate document class. 物料的订单存储在单独的文档类中。
I can move and change the order of the items, but I would like to update the document class whenever the QListWidget order is modified through a drag&drop. 我可以移动和更改项目的顺序,但是只要通过拖放修改QListWidget的顺序,我都想更新文档类。
This is the abstract idea: 这是抽象的想法:
myListWidget::myListWidget(QWidget *parent) : QListWidget(parent)
{
/*option*/ connect(...);
/*option*/ setDragDropMode(QAbstractItemView::InternalMove);
}
void myListWidget::updateOrder()
{
for(i=0; i<count(); i++) {
...function that updates the other class by QListWidget::item(int row)
}
}
I have seen that there is no drop signal for the QListWidget
, so I tried to associate the signal with the subclass model through: 我已经看到
QListWidget
没有下降信号,所以我尝试通过以下方式将信号与子类模型相关联:
connect(model(), SIGNAL(layoutChanged()), this, SLOT(updateOrder()));
This didn't work. 这没用。
Can somebody suggest how to achieve my goal? 有人可以建议如何实现我的目标吗?
Have you tried to reimplement dropEvent in myListWidget? 您是否尝试过在myListWidget中重新实现dropEvent?
http://doc.qt.io/qt-5/qlistwidget.html#dropEvent http://doc.qt.io/qt-5/qlistwidget.html#dropEvent
"This event handler is called when the drag is dropped on this widget. The event is passed in the event parameter." “将拖动拖放到此小部件上时将调用此事件处理程序。该事件在event参数中传递。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.