Can't make child in Qtreeview using QStandardItemModel
-
Hi
after reading some examples i still missing here something .
i have Qtreeview for view and QStandardItemModel for the data interface , also using QSortFilterProxyModel subclass but i dont know if its relevant.
this is my logic :
first i create the model with the QWidget as the parent :
@QStandardItemModel m_model = new QStandardItemModel(0,4,parent);
then setSourceModel(m_model) for the widget
set the treeview with QSortFilterProxyModel. something like this :
GroupProxyModel = new GroupSortFilterProxyModel;
GroupProxyModel->setDynamicSortFilter(true);
setSourceModel(createSubjectModel(parent));ui.treeView_mainwindow->setModel(GroupProxyModel);
ui.treeView_mainwindow->setSortingEnabled(true);@then later i fill the first row like this :
@QList<QStandardItem *> items;
items.insert(0,new QStandardItem("Test 0"));
items.at(0)->setEditable(false);
m_model->insertRow(0,items);@until now every thing working fine and i see the row with the data . but when i like to
add child to the row like this :@QModelIndex parentQModelIndex = m_model->item(0,0)->index();
m_model->insertRows(0,1,parentQModelIndex);
m_model->insertColumns(0,1,parentQModelIndex);
QModelIndex indexB = m_model->index(0, 0, parentQModelIndex);
m_model->setData(indexB,"Child test",Qt::DisplayRole);@
but i dont see the child , why ? -
Try to use QStandardItemModel directly with your QTreeView. If you can see the "child" then the problem is with your GroupSortFilterProxyModel which in your case is located between QTreeView and QStandardItemModel.