【发布时间】:2010-12-27 03:23:26
【问题描述】:
我在使用可以通过拖放重新排序的自定义项来实现 QListWidget 时遇到问题。问题是当我在一个项目上快速双击(非常短的拖放)时,该项目有时会从 QListWidget 中消失。
这是我的 Widget 的构造函数:
ListPopisiDragDrop::ListPopisiDragDrop(QWidget *parent) :
QListWidget(parent)
{
setSelectionMode(QAbstractItemView::SingleSelection);
setDragEnabled(true);
viewport()->setAcceptDrops(true);
setDefaultDropAction(Qt::MoveAction);
setDropIndicatorShown(true);
setDragDropMode(QAbstractItemView::InternalMove);
}
还有 drop 事件:
void ListPopisiDragDrop::dropEvent(QDropEvent *event){
int startRow=currentIndex().row();
QListWidget::dropEvent(event);
int endRow=currentIndex().row();
//more code...
}
自定义项目是通过实现 QAbstractItemDelegate 中的 paint() 和 sizeHint() 函数来制作的。
当物品消失的问题发生时,dropEvent 甚至不会被调用。
我真的不知道发生了什么,也不知道我是否做错了什么。任何帮助表示赞赏。
谢谢!
编辑: 我在 Symbian S60 第 5 版手机上运行该应用程序。
编辑2: 如果我将此行添加到构造函数:
setDragDropOverwriteMode(true);
列表中的项目仍然消失,但空行留在原处。
编辑3: 我添加了这段代码来看看发生了什么:
bool ListPopisiDragDrop::event(QEvent *e){
qDebug()<<"new event, type: "<<e->type()<<", listCount: "<<this->count();
QListWidget::event(e);
}
当调用 drop 事件时,我还打印了“drop event”。这给了我以下输出:
...
[Qt Message] new event, type: 12 , listCount: 2
[Qt Message] new event, type: 12 , listCount: 2
[Qt Message] new event, type: 68 , listCount: 2
[Qt Message] DROPEVENT
[Qt Message] new event, type: 71 , listCount: 2
[Qt Message] new event, type: 12 , listCount: 2
[Qt Message] new event, type: 12 , listCount: 2
[Qt Message] new event, type: 68 , listCount: 2
[Qt Message] DROPEVENT
[Qt Message] new event, type: 71 , listCount: 2
[Qt Message] new event, type: 12 , listCount: 2
[Qt Message] new event, type: 12 , listCount: 2
[Qt Message] new event, type: 12 , listCount: 2
[Qt Message] new event, type: 68 , listCount: 2
[Qt Message] new event, type: 12 , listCount: 1
[Qt Message] new event, type: 12 , listCount: 1
[Qt Message] new event, type: 1 , listCount: 1
...
如您所见,在事件类型 68 之后,listCount 从 2 变为 1(一项消失)。我仍然没有找到问题所在......
编辑4: 即使我不使用自定义项目,我也有相同的行为。还是不知道怎么回事。
编辑5: 即使是 [1] 中的示例在移动设备上进行测试时也具有相同的行为。 Qt版本会不会有问题?我正在为 Symbian 设备版本 4.6.3 使用 Qt...
[1]http://www.java2s.com/Code/Cpp/Qt/QListWidgetdraganddrop.htm
【问题讨论】:
-
type 68 = ChildAdded, 71 = ChildRemoved, 12 = Paint, 1 = Timer
标签: qt drag-and-drop symbian qlistwidget