How to programmatically select multiple rows in QListView?
-
wrote on 21 Jan 2021, 03:51 last edited by
I have written a program where the user can select multiple rows from a QListView. Sometimes the program need to load a set of selection at startup, so the program needs to be able to select multiple rows from code. How can this be done?
-
wrote on 21 Jan 2021, 05:05 last edited by
Use the correct QListView method to get the container of items in the list, iterate through it, and set the "checked/selected" attribute for each item that matches your selection cirteria.
-
wrote on 21 Jan 2021, 05:48 last edited by ablan
Sorry, can you show me how it is written in code?
-
You should take a look at QItemSelectionModel::select()
-
You should take a look at QItemSelectionModel::select()
wrote on 22 Jan 2021, 02:59 last edited by@Christian-Ehrlicher
Ok thanks! I got it to work.
5/5