我将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
it视频: https://mega.nz/#!bkoTDQSI!YgVn6jIAPJ86fhexzsGySbhrPwQAK5IwlTTeb5L-sQ4
问题是,我希望在与被删除项相关的删除之后立即以编程方式执行操作
我想在拖放后展开项目并选择它。右侧的视图取决于当前索引
我什么都试过了。在以下情况下进行选择:
没有任何效果,因为如果我尝试在这些方法之后更改选择,我会在内部中断Qt,导致未终止的删除无法正常工作。我需要等待从drop派生的所有信号完成,以执行select和expand命令
我很绝望,我观察了TreeWidget的行为,遇到了和我一样的问题:当拖放时,选择的行错误,节点崩溃
他们在Qt论坛上为我解决了这个问题
我通过在
connect
中添加参数QtCore.Qt.QueuedConnection
来连接自定义信号这里是解决方案:
https://forum.qt.io/topic/114716/treeview-wait-until-the-drop-is-complete-to-perform-another-action/3
相关问题 更多 >
编程相关推荐