Seite 1 von 1

[solved]Drag & Drop zw. 2 QListView Einträgen

Verfasst: 6. Mai 2012 15:31
von hakaishi
Hallo zusammen,

ich habe in einem QListView Ordner aufgelistet und in einem zweiten die Dateien (mittels QFileSystemModel) und würde gerne die Dateien von einem Ordner in einen anderen verschieben.

Folgendes habe ich versucht:

Code: Alles auswählen

     splitter = new QSplitter(centralwidget);
     gridLayout->addWidget(splitter, 0, 0);

     fModel = new QFileSystemModel(this);
     fModel->setRootPath(origPath);
     fModel->setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
     fModel->setSupportedDragActions(Qt::MoveAction);

     nModel = new QFileSystemModel(this);
     nModel->setRootPath(origPath); //just as an example
     nModel->setFilter(QDir::Files);
     nModel->setSupportedDragActions(Qt::MoveAction);

     nbList = new QListView(splitter); //note book list
     nbList->setModel(fModel);
     nbList->setRootIndex(fModel->index(origPath));
     nbList->setContextMenuPolicy(Qt::CustomContextMenu);
     nbList->setDefaultDropAction(Qt::MoveAction);
     nbList->setDragDropMode(QAbstractItemView::DropOnly);
     nbList->setSelectionMode(QAbstractItemView::ExtendedSelection);
     nbList->setDropIndicatorShown(true);

     nList = new QListView(splitter);  //note list
     nList->setModel(nModel);
     nList->setRootIndex(nModel->index(origPath));
     nList->setContextMenuPolicy(Qt::CustomContextMenu);
     nList->setDragDropMode(QAbstractItemView::DragOnly);
     nList->setSelectionMode(QAbstractItemView::ExtendedSelection);
     nList->setDropIndicatorShown(true);
Aber das funktioniert so anscheinend nicht... kann mir bitte jemand auf die Sprünge helfen?

Viele Grüße, Hakaishi

Re: Drag & Drop zw. 2 QListView Einträgen

Verfasst: 6. Mai 2012 16:28
von hakaishi
Der vollständige Code liegt hier: https://github.com/hakaishi/nobleNote

Re: Drag & Drop zw. 2 QListView Einträgen

Verfasst: 8. Mai 2012 19:50
von hakaishi
Kann mir niemand einen Tipp geben, was falsch ist bzw. was fehlt?

Re: Drag & Drop zw. 2 QListView Einträgen

Verfasst: 8. Mai 2012 21:15
von Christian81
Im Code ist noch gar nichts für Drag'n'Drop vorbereitet. Wie Drag'n'Drop funktioniert steht hier: http://doc.trolltech.com/4.7/examples-draganddrop.html

Re: Drag & Drop zw. 2 QListView Einträgen

Verfasst: 10. Mai 2012 20:55
von hakaishi
Ok, damit funktioniert es jetzt:

Code: Alles auswählen

     QList<QListView*> listViews;
     listViews << folderList << noteList;
     foreach(QListView* list, listViews)
     {
        list->setContextMenuPolicy(Qt::CustomContextMenu);

        list->setDragDropMode(QAbstractItemView::DragDrop);
        list->viewport()->setAcceptDrops(true);
        list->setDropIndicatorShown(true);
        list->setDefaultDropAction(Qt::MoveAction);
     }
     noteList->setDragEnabled(true);
     folderList->setDragEnabled(false);
Gruß, Hakaishi