拖放QTreeView,removeRows未调用 [英] Drag and drop in QTreeView, removeRows not called
问题描述
我在 QTreeView
中拖放有一些问题:
I have some problem with drag and drop in QTreeView
:
我将标志设置为 Qt :: MoveAction
并重新实现 removeRows()
, dropMimeData()
等在我的模型模型继承 QAbstractItemModel
。
I set flag to Qt::MoveAction
and reimplemented removeRows()
, dropMimeData()
and etc in my model. The Model inherits QAbstractItemModel
.
当我拖放时, mimeData()
, dropMimeData()
被自动调用,
和$ code> dropMimeData() code> insertRows()自动执行。但是 removeRows()
未被调用,所以拖动的项目仍然存在。我googled,但他们说他们的 removeRows()
被自动调用。
When I drag and drop, mimeData()
, dropMimeData()
are called automatically,
and also dropMimeData()
calls insertRows()
automatcally. But removeRows()
is not called, so the dragged item is still alive. I googled, but they said their removeRows()
was called automatically.
- 为什么在
dropMimeData()
之后调用的不是我的removeRows()
? - 在
dropMimeData()
中手动调用removeRows()
/ li>
- 如果是,我如何知道之前的
QModelIndex
的开始拖动?
- Why isn't my
removeRows()
called afterdropMimeData()
? - Shoud I call
removeRows()
manually indropMimeData()
? - If so, how can I know the previous
QModelIndex
of start of drag?
当开始拖动时,在 mimeData()
中,我可以将私人成员保存索引,但看起来不太好。
When starting drag, in mimeData()
, I can save index in private member, but it looks like not good.
任何建议将不胜感激。
Any advice would be appreciated.
推荐答案
我想是的,你必须调用 removeRows()
如果 Qt :: DropAction
是 Qt :: MoveAction $,则$ code> dropMimeData()
c $ c>,即您将树节点从一个地方完全移动到另一个地方。
I think yes, you have to call removeRows()
from the dropMimeData()
if the Qt::DropAction
is Qt::MoveAction
, i.e. you completely move your tree node from one place to another.
WRT你的第二个问题,你可以在<$ c $中创建自定义的MIME数据c> QAbstractItemModel :: mimeData()并对您拖动的节点的初始信息进行编码。因此,在$ code> dropMimeData()函数中,您可以解码并使用它。
WRT your second question, you can create your custom mime data in QAbstractItemModel::mimeData()
and encode your dragged nodes initial information there. So, in dropMimeData()
function you can decode and use it.
这篇关于拖放QTreeView,removeRows未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!