在 PyQt 中通过拖放重新排序 QTreeWidget 中的项目
我有一个 QTreeWidget,其中包含我认为所有正确的设置设置,以便能够通过拖动项目来重新排序项目。有时它可以工作,但通常情况下,我将一个项目拖到另一个项目中,它要么消失,要么变成一个子项目。
有什么办法可以防止这种情况发生,这样您就不会丢失尝试重新订购的商品吗?我想你可以在 Qt Designer 中实现这一点。我将 dragDrop 模式设置为 InternalMove,并将 defaultDropAction 设置为 MoveAction,但我什至不确定这两个是否是我需要调整的。
提前致谢!
I have a QTreeWidget with what I thought all the proper settings setup in order to be able to reorder items by dragging them around. It can work, at times, but more often than not I drag an item into another one and it either disappears or becomes a child.
Is there anyway to prevent this from happening so you don't lose items you're trying to reorder? I figured you could achieve this within Qt Designer. I have dragDrop mode set to InternalMove and defaultDropAction set to MoveAction, but I'm not even certain of both of those are what I need to be adjusting.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以向单个树小部件项目添加标志来控制拖放行为(除其他外)。例如,要防止某个项目成为放置目标,请尝试如下操作:
有关更多详细信息,请参阅:Qt.ItemFlags
You can add flags to individual tree widget items that control drag and drop behaviour (amongst other things). For instance, to prevent an item being a drop target, try something like this:
For more details, see: Qt.ItemFlags