qlistwidget symbianのリストから消えるドラッグアンドドロップアイテム
-
13-10-2019 - |
質問
ドラッグしてドロップすることで並べ替えることができるカスタムアイテムを使用して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 5th Edition電話でアプリケーションを実行しています。
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の後、リストカウントが2から1に変更されます(1つのアイテムが消えます)。私はまだ問題を把握していません...
edit4:カスタムアイテムを使用していない場合でも、同じ動作をしています。まだ何が悪いのかわからない。
edit5:[1]の例でさえ、モバイルデバイスでテストすると同じ動作があります。 QTバージョンは問題になる可能性がありますか? Symbian Devicesバージョン4.6.3にQTを使用しています...
1] http://www.java2s.com/code/cpp/qt/qlistwidgetdraganddrop.htm
解決
この動作の2つの理由を考えることができます。信号項目doubleclicklickedがqlistwidgetのどこかで処理され、unintendetの何かを行うか、Sourceと宛先が同じである場合、Dropeventの「より多くのコード」が悪いことをします(Startrowが等しいかどうかを確認できますこの場合、断念して何もしません)。
編集:
このプログラムはあなたのために機能しますか:
#include <QApplication>
#include <QListWidget>
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QListWidget lw;
for(int i = 1; i < 10; ++i)
lw.addItem(new QListWidgetItem(QString("Item %1").arg(i)));
lw.setDragEnabled(true); // ***
lw.viewport()->setAcceptDrops(true); // ***
lw.setDefaultDropAction(Qt::MoveAction); // ***
lw.setDropIndicatorShown(true); // ***
lw.setDragDropMode(QAbstractItemView::InternalMove);
lw.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
a.exec();
}
3つ星のある線を削除できます。このプログラムは、VS2010でコンパイルされたQT 4.7.1を備えたWindows XPで機能します。
他のヒント
デスクトップで同じ問題があり、選択モード、internalMoveなどが表示されています。また、ビューのための私自身のモデルがあったので、私はそれをそのように戻させました:
Qt::ItemFlags MyModel::flags(const QModelIndex& index) const
{
if (index.isValid())
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
}
私と一緒にうまくいきました。