使用PyQt中的拖放功能对QTreeWidget中的项目进行重新排序 [英] Reordering items in a QTreeWidget with Drag and Drop in PyQt

查看:592
本文介绍了使用PyQt中的拖放功能对QTreeWidget中的项目进行重新排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个QTreeWidget,它具有我认为所有正确设置的设置,以便能够通过拖动来重新排序项目。有时它可以工作,但是我经常将一项拖到另一个项目中,它消失或变成孩子。

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.

是否有阻止这种情况发生的方法,这样您就不会丢失要重新订购的商品?我认为您可以在Qt Designer中实现这一目标。我已经将 dragDrop 模式设置为InternalMove,将 defaultDropAction 设置为MoveAction,但是我不确定这两个都是我需要调整的。

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.

预先感谢!

推荐答案

您可以将标志添加到单个树小部件项目中,控制拖放行为(以及其他操作)。例如,要防止某物品成为放置目标,请尝试以下操作:

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:

item = QTreeWidgetItem(parent)
item.setFlags(items.flags() & ~Qt.ItemIsDropEnabled)

请参阅qt文档有关更多详细信息: http://doc.qt.nokia.com/4.7 /qt.html#ItemFlag-enum

See the qt docs for more details: http://doc.qt.nokia.com/4.7/qt.html#ItemFlag-enum

这篇关于使用PyQt中的拖放功能对QTreeWidget中的项目进行重新排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆