i have treeView based on QAbstractItemModel, but now i don’t know how to set multiple selection in my model
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I assume you are going to want to do this programmatically?
Firstly, selections are not controlled by the model, but by the view. This is because a model can be connected to multiple views, each of which can have a different selection (the views are independent, except for the data they show from the model).
Ayway, you will want to get the “selection Model” from the treeview
selection_model = treeview.selectionModel()And then you can call
repeatedly to select what ever items you like, based on the
model_indexspecified (you can find the index of a row for a QStandardItem() by callingindexFromItem(item)on the data model (not the selection model).Anyway, I suggest you look up the documentation for treeview selectionModels as this will help you further (can’t really help much more without more information than a single line question!)