• 7887阅读
  • 6回复

QTreeWidget自拖放问题 [复制链接]

上一主题 下一主题
离线hejunjun
 
只看楼主 倒序阅读 楼主  发表于: 2011-07-13
关键词: QTreeWidget
自己继承QTreeWidget实现自我拖放操作,继承了dropEvent之后,拖动然后释放会直接删除。这个谁能解释下是什么原因。
谁有子拖放的demo和好的想法可以讨论下。
离线hejunjun
只看该作者 1楼 发表于: 2011-07-13
在线等啊UP!
离线alexltr

只看该作者 2楼 发表于: 2011-07-13
看看下面的內容是否有幫助:

Since access to the data displayed by the view is controlled by a model, the model used also has to provide support for drag and drop operations. The actions supported by a model can be specified by reimplementing the QAbstractItemModel::supportedDropActions() function. For example, copy and move operations are enabled with the following code:

Qt::DropActions DragDropListModel::supportedDropActions() const
{
     return Qt::CopyAction | Qt::MoveAction;
}

Although any combination of values from Qt::DropActions can be given, the model needs to be written to support them. For example, to allow Qt::MoveAction to be used properly with a list model, the model must provide an implementation of QAbstractItemModel::removeRows(), either directly or by inheriting the implementation from its base class.
我不从事IT,只是喜欢Qt。
我不是程序员,只是与程序有缘。
我写程序,只是为了让工作变得简单有序!

                      ----  一个一直在入门的编程学习者
离线hejunjun
只看该作者 3楼 发表于: 2011-07-14
我试了下,加入这个模型,自己继承QTreeWidget之后再重写dropEvent事件,加入不加这段代码,在自我item拖拽时,拖拽的item还是会消失。这是QT对于QTreeWidget继承dropEvent就是这么设计的。还是我忽略了什么。
离线alexltr

只看该作者 4楼 发表于: 2011-07-14
如果不要刪除, 是不是不要Qt::MoveAction?

Qt::DropActions DragDropListModel::supportedDropActions() const
{
     return Qt::CopyAction;
}
我不从事IT,只是喜欢Qt。
我不是程序员,只是与程序有缘。
我写程序,只是为了让工作变得简单有序!

                      ----  一个一直在入门的编程学习者
离线hejunjun
只看该作者 5楼 发表于: 2011-07-14
UP!
离线hejunjun
只看该作者 6楼 发表于: 2011-07-14
alexltr 是正解.....没早点看到,我都自己继承判断实现完了 我看我和QT底层实现是一样的么.......
快速回复
限100 字节
 
上一个 下一个