I'm having trouble implementing a QListWidget with custom items that can be reordered by dragging and dropping. The problem is when I make a fast double click (a very short drag&drop) on an item, the item sometimes disappears from the QListWidget.
This is the constructor for my Widget:
ListPopisiDragDrop::ListPopisiDragDrop(QWidget *parent) :
QListWidget(parent)
{
setSelectionMode(QAbstractItemView::SingleSelection);
setDragEnabled(true);
viewport()->setAcceptDrops(true);
setDefaultDropAction(Qt::MoveAction);
setDropIndicatorShown(true);
setDragDropMode(QAbstractItemView::InternalMove);
}
also the drop event:
void ListPopisiDragDrop::dropEvent(QDropEvent *event){
int startRow=currentIndex().row();
QListWidget::dropEvent(event);
int endRow=currentIndex().row();
//more code...
}
Custom items are made by implementing paint() and sizeHint() functions from QAbstractItemDelegate.
When the problem with disappearing items happens, the dropEvent isn't even called.
I really don't know what is happening and if I'm doing something wrong. Any help is appreciated.
Thanks!
Edit: I'm running the application on a Symbian S60 5th edition phone.
Edit2: If I add this line to the constructor:
setDragDropOverwriteMode(true);
the item in the list still disappears, but an empty row stays in it's place.
Edit3: I've added this code to see what is happening:
bool ListPopisiDragDrop::event(QEvent *e){
qDebug()<<"new event, type: "<<e->type()<<", listCount: "<<this->count();
QListWidget::event(e);
}
I've also printed "drop event" when the drop event is called. This gives me the following output:
...
[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
...
As you can see, after event type 68, the listCount changes from 2 to 1 (one item disappears). I'm still not getting where the problem is...
Edit4: I'm having the same behavior even when I'm not using custom items. Still can't figure out what's wrong.
Edit5: Even the example from [1] has the same behavior when tested on the mobile device. Could the Qt version be a problem? I'm using Qt for Symbian Devices version 4.6.3...
[1]http://www.java2s.com/Code/Cpp/Qt/QListWidgetdraganddrop.htm