I am trying to make a dialog with two lists, where items can be moved between each list, like so:



I am using a QListView and QStringListModel. How can i move the selected items from one list model to the other?

This is what i have got so far:
Qt Code:
  1. void moveToRight() {
  2. QStringListModel* leftModel = (QStringListModel*)leftListView->model();
  3. QStringListModel* rightModel = (QStringListModel*)rightListView->model();
  4.  
  5. leftListView->setUpdatesEnabled(false);
  6. rightListView->setUpdatesEnabled(false);
  7.  
  8. QModelIndexList indexes = leftListView->selectionModel()->selectedIndexes();
  9. qSort(indexes.begin(), indexes.end());
  10.  
  11. // Add the selected items to the right list
  12. for (int i = 0; i < indexes.count(); i++) {
  13. //rightModel->insertRow(indexes.at(i).row());
  14. // I'm guessing i could get the QStringList from the model
  15. // and add to that.
  16. }
  17.  
  18. // Then remove them from the left list
  19. for (int i = indexes.count() - 1; i > -1; --i) {
  20. leftModel->removeRow(0);
  21. }
  22.  
  23. leftListView->setUpdatesEnabled(true);
  24. rightListView->setUpdatesEnabled(true);
  25. }
To copy to clipboard, switch view to plain text mode 

I do not yet know of a way to add the items to the other model. Also, the removing doesn't seem to work.