c++ - Selecting a row in QTreeView programmatically -


i have qtreeview qfilesystemmodel model.

the qtreeview has selectionbehavior set selectrows.

in code read dataset select , select them via:

idx = treeview->model()->index(search);  selection->select(idx, qitemselectionmodel::select); 

this selects cell, not row . .

have added stupid workaround, rather fix correct way.

for (int col=0; col< treeview->model()->columncount(); col++)  {     idx = treeview->model()->index(search, col);     selection->select(idx, qitemselectionmodel::select);  }  

or ^^ way it?

you can select entire row using qitemselection:

selection->select (     qitemselection (         treeview->model ()->index (search, 0),         treeview->model ()->index (search, treeview->model ()->columncount () - 1)),     qitemselectionmodel::select); 

also if want row selection user clicks need set selection behavior:

treeview->setselectionbehavior (qabstractitemview::selectrows) 

Comments

Popular posts from this blog

php - How to build a web site which gives a sub-domain dynamically to every registered user? -

c# - Add item to Generic List / Collection using reflection -