Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't make child in Qtreeview using QStandardItemModel
Qt 6.11 is out! See what's new in the release blog

Can't make child in Qtreeview using QStandardItemModel

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dakron
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved