QTreeView - 等待拖放完成再执行另一个操作
QTreeView - Wait until the drop is complete to perform another action
我将 TreeView 与 MyTreeModel(继承自 QAbstractItemModel)一起使用。该模型由文档中显示的带有节点的树结构提供。
https://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html
https://doc.qt.io/qt-5/qtwidgets-itemviews-editabletreemodel-example.html
https://doc.qt.io/qt-5/model-view-programming.html#using-drag-and-drop-with-item-views
我完美地实现了在树的元素之间拖放的整个主题。正如文档所说,我已经为它重新实现了 mimeData、mimeTypes 和 dropMimeData。
它的视频:
https://mega.nz/#!bkoTDQSI!YgVn6jIAPJ86fhexzsGySbhrPwQAK5IwlTTeb5L-sQ4
问题是我想在与被丢弃的项目相关的丢弃之后立即以编程方式执行操作。
我想展开下拉后的项目,我想select它。右边的视图取决于currentIndex。
我什么都试过了。在:
之后生成 selection
- 已插入行数
- 数据已更改
- currentChanged
- 变化事件
- dropEvent
- 事件过滤器
没有任何效果,因为如果我尝试在这些方法之后更改 selection,我会在内部破坏 Qt,导致未终止的下降无法正常工作。我需要等待从下降派生的所有信号完成才能执行 select 和扩展命令。
我很绝望,我观察了 TreeWidget 的行为并且遇到了与我相同的问题:当放置时行 selected 是错误的并且节点崩溃了。
他们已经在 Qt 论坛上为我解决了。
我已通过在 connect
中添加参数 QtCore.Qt.QueuedConnection
来连接自定义信号。
- I'm not sure why anything should break. Run your model throught the model test to make sure it's implemented 100% according to Qt's
expectation
- adding
Qt::QueuedConnection
as the 5th argument of your connect
ststement should ensure your code gets executed after the move is
completed and control is given back to Qt's event loop
我将 TreeView 与 MyTreeModel(继承自 QAbstractItemModel)一起使用。该模型由文档中显示的带有节点的树结构提供。
https://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html
https://doc.qt.io/qt-5/qtwidgets-itemviews-editabletreemodel-example.html
https://doc.qt.io/qt-5/model-view-programming.html#using-drag-and-drop-with-item-views
我完美地实现了在树的元素之间拖放的整个主题。正如文档所说,我已经为它重新实现了 mimeData、mimeTypes 和 dropMimeData。
它的视频: https://mega.nz/#!bkoTDQSI!YgVn6jIAPJ86fhexzsGySbhrPwQAK5IwlTTeb5L-sQ4
问题是我想在与被丢弃的项目相关的丢弃之后立即以编程方式执行操作。
我想展开下拉后的项目,我想select它。右边的视图取决于currentIndex。
我什么都试过了。在:
之后生成 selection- 已插入行数
- 数据已更改
- currentChanged
- 变化事件
- dropEvent
- 事件过滤器
没有任何效果,因为如果我尝试在这些方法之后更改 selection,我会在内部破坏 Qt,导致未终止的下降无法正常工作。我需要等待从下降派生的所有信号完成才能执行 select 和扩展命令。
我很绝望,我观察了 TreeWidget 的行为并且遇到了与我相同的问题:当放置时行 selected 是错误的并且节点崩溃了。
他们已经在 Qt 论坛上为我解决了。
我已通过在 connect
中添加参数 QtCore.Qt.QueuedConnection
来连接自定义信号。
- I'm not sure why anything should break. Run your model throught the model test to make sure it's implemented 100% according to Qt's expectation
- adding
Qt::QueuedConnection
as the 5th argument of yourconnect
ststement should ensure your code gets executed after the move is completed and control is given back to Qt's event loop