Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Qtreeview multilevel child auto select

$
0
0
how to implement a recursive function to auto select all the children of a root item inside QTreeview model and then give user, the ability to deselect each one he wishes! Note: each child also can have children. deselect occurs one by one. below code selects all the children successfully but i don’t know how to implement deselect !! QObject::connect(ui->trvView, SIGNAL(clicked(QModelIndex)), this, SLOT(itemSelected(QModelIndex))); void TrustChain::itemSelected(QModelIndex index) {     QModelIndex childIndex;     if(!index.isValid())     {         return;     }       selectedItem = chainModel->itemFromIndex(index);     if(!selectedItem)     {         return;     }       ui->trvView->selectionModel()->select(index, QItemSelectionModel::Select);     for(int i = 0; i < selectedItem->rowCount(); i++)     {         childIndex = chainModel->index(i, 0, index);         ui->trvView->selectionModel()->select(childIndex, QItemSelectionModel::Select);         itemSelected(childIndex);         while (selectedItem->parent() != 0)         {             selectedItem = selectedItem->parent();         }     } }

Viewing all articles
Browse latest Browse all 13965

Trending Articles