gig-raf
25th January 2016, 21:48
Dear ALl,
I have a question that I am hoping someone in the Forum can help me with.
I have QtableView, using the QStandardItemModel. I need to be able to sort/arrange the content of the model by dragging and dropping its items. Is this possible with the QStandarItemModel and QTableView?
so in short I would be able to drag item2 and drop it on top of item1 - result should be that item1 and item2 swap place. I do not want to drop between, only on top of other items. No new lines should be created....
I am configuring the QTableView the following way.
...
tableView->setContextMenuPolicy(Qt::CustomContextMenu);
tableView->setSelectionBehavior(QAbstractItemView::SelectItem s);
tableView->setAlternatingRowColors(true);
tableView->setDropIndicatorShown(true);
tableView->setDragDropOverwriteMode(false);
tableView->setDragEnabled(true);
tableView->setDragDropMode(QAbstractItemView::InternalMove);
tableView->setDragDropMode(QAbstractItemView::DragDrop);
...
BUt if I drag item1 and drop on item2 nothing happens. If I drag item1 and drop it between item2 and item3. item1 is appended to the model at the very bottom.??
Any help is most appreciated.
I have a question that I am hoping someone in the Forum can help me with.
I have QtableView, using the QStandardItemModel. I need to be able to sort/arrange the content of the model by dragging and dropping its items. Is this possible with the QStandarItemModel and QTableView?
so in short I would be able to drag item2 and drop it on top of item1 - result should be that item1 and item2 swap place. I do not want to drop between, only on top of other items. No new lines should be created....
I am configuring the QTableView the following way.
...
tableView->setContextMenuPolicy(Qt::CustomContextMenu);
tableView->setSelectionBehavior(QAbstractItemView::SelectItem s);
tableView->setAlternatingRowColors(true);
tableView->setDropIndicatorShown(true);
tableView->setDragDropOverwriteMode(false);
tableView->setDragEnabled(true);
tableView->setDragDropMode(QAbstractItemView::InternalMove);
tableView->setDragDropMode(QAbstractItemView::DragDrop);
...
BUt if I drag item1 and drop on item2 nothing happens. If I drag item1 and drop it between item2 and item3. item1 is appended to the model at the very bottom.??
Any help is most appreciated.