Check if you have to sort the list at all. As far as I remember it is already sorted and sorting a sorted list is an expensive operation.
Check if you have to sort the list at all. As far as I remember it is already sorted and sorting a sorted list is an expensive operation.
Since I also wasn't sure, I've looked up and found:So you have to sort the list.QModelIndexList QItemSelectionModel::selectedIndexes () const
Returns a list of all selected model item indexes. The list contains no duplicates, and is not sorted.
Hello Guys,
I just had the same question, thanks for resolving!
But there is something more I'm interested in:
I want to connect the "removing"-thing with a button. How does this work?
Qt Code:
ui->listView->setUpdatesEnabled(false); QModelIndexList indexes = ui->listView->selectionModel()->selectedIndexes(); qSort(indexes.begin(), indexes.end()); for(int i = indexes.count() - 1; i > -1; --i) model->removeRow(indexes.at(i).row()); ui->listView->setUpdatesEnabled(true);To copy to clipboard, switch view to plain text mode
I ment the way to remove a list of selected items in the QListView.
Now I want to connect this with a button (called "Delete"). If you select the items and press delete-button, they shall be removed with that.
Thanks for beeing interested in my problem! I would be happy to read an idea, not the whole solving please.
So what is the problem? Make a signal-slot connection and put your code in a custom slot of yours.
No problem, I actually did this before.
But I got my items from a rootpath. So I dont geht the updates "deleted-list", no he always shows me the pathlist.
Last edited by Bloody; 14th September 2012 at 10:09.
Sorry, that I could not answer these days. So actually I want help..
To my problem: I want a listfiew displaying files from a rootpath. 'Till here the top solution is pretty helpful. But the next step I want to go is to delete some selected files but the solution in this thread is not working as I want to.
I select items i want to delete(working well), press the "delete files" button and nothing happens. I guess the problem here is the self-updating listview. Over and above I actually want to build a "copy-program". Therefor you select some files from the listview and press "delete". Then you "save" the rest in a new folder. The system creates a new folder in any path with a copy of the left files in the listfiew.
But back to my update problem: If I press delete, nothing happens... ? And if I create new files in my path, they self-update into the listview. My idea: How to create listviewitems which are actually files able to be deleted out of the listview? How about this idea?
QFileSystemModel provides simple interface to operate on local file system. If you connect this with a List View I think it will sort out your problem.
Bookmarks