QTreeView等待放置完成后再执行另一个操作

2024-10-06 09:56:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我将TreeView与MyTreeModel(从QAbstractItemModel继承)一起使用。该模型由一个树形结构提供,其节点如文档中所示

我已经完美地实现了在树的元素之间进行拖放的整个主题。正如医生所说,我已经为它重新实现了mimeData、mimeTypes和dropMimeData

it视频: https://mega.nz/#!bkoTDQSI!YgVn6jIAPJ86fhexzsGySbhrPwQAK5IwlTTeb5L-sQ4

问题是,我希望在与被删除项相关的删除之后立即以编程方式执行操作

我想在拖放后展开项目并选择它。右侧的视图取决于当前索引

我什么都试过了。在以下情况下进行选择:

  • 划船
  • 数据更改
  • 电流变化
  • 变更事件
  • dropEvent
  • 事件过滤器

没有任何效果,因为如果我尝试在这些方法之后更改选择,我会在内部中断Qt,导致未终止的删除无法正常工作。我需要等待从drop派生的所有信号完成,以执行select和expand命令

我很绝望,我观察了TreeWidget的行为,遇到了和我一样的问题:当拖放时,选择的行错误,节点崩溃


Tags: httpsio模型doc节点examplehtml事件
1条回答
网友
1楼 · 发布于 2024-10-06 09:56:49

他们在Qt论坛上为我解决了这个问题

我通过在connect中添加参数QtCore.Qt.QueuedConnection来连接自定义信号

这里是解决方案:
https://forum.qt.io/topic/114716/treeview-wait-until-the-drop-is-complete-to-perform-another-action/3

  1. 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
  2. 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

相关问题 更多 >