ドラッグ アンド ドロップで並べ替えることができるカスタム アイテムを含む QListWidget の実装に問題があります。問題は、アイテムをすばやくダブルクリック (非常に短いドラッグ アンド ドロップ) すると、アイテムが QListWidget から消えることがあります。
これは私のウィジェットのコンストラクタです:
ListPopisiDragDrop::ListPopisiDragDrop(QWidget *parent) :
QListWidget(parent)
{
setSelectionMode(QAbstractItemView::SingleSelection);
setDragEnabled(true);
viewport()->setAcceptDrops(true);
setDefaultDropAction(Qt::MoveAction);
setDropIndicatorShown(true);
setDragDropMode(QAbstractItemView::InternalMove);
}
また、ドロップイベント:
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 版の電話でアプリケーションを実行しています。
Edit2:この行をコンストラクターに追加すると:
setDragDropOverwriteMode(true);
リスト内のアイテムは引き続き消えますが、空の行はその場所に残ります。
Edit3:何が起こっているかを確認するために、このコードを追加しました:
bool ListPopisiDragDrop::event(QEvent *e){
qDebug()<<"new event, type: "<<e->type()<<", listCount: "<<this->count();
QListWidget::event(e);
}
ドロップイベントが呼び出されたときに「ドロップイベント」も出力しました。これにより、次の出力が得られます。
...
[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 に変更されます (1 つの項目が消えます)。どこが問題なのか未だに掴めず…
Edit4: カスタム アイテムを使用していない場合でも、同じ動作をしています。何が問題なのかまだわかりません。
Edit5: [1] の例でさえ、モバイル デバイスでテストすると同じ動作をします。Qt のバージョンが問題になる可能性はありますか? Qt for Symbian Devices バージョン 4.6.3 を使用しています...
[1]http://www.java2s.com/Code/Cpp/Qt/QListWidgetdraganddrop.htm