Important: Please read the Qt Code of Conduct -

How can i set QStandardItem in the row which have parents?

  • How can i set QStandardItem in the row which have parents?
    For example:

    I need set item here, but there is no functions which would allow to do it.
    There is to functions to set item:
    setItem ( int row, int column, QStandardItem * item )
    setItem ( int row, QStandardItem * item )
    But they dont have parent argument

  • I don't understand your problem.
    If you want to set a tree with 3 levels , you just have to do :

    @QStandardItemModel *model = new QStandardItemModel;
    QStandardItem * level0 = new QStandardItem("level 0");
    QStandardItem * level1 = new QStandardItem("level 1");
    QStandardItem * level2 = new QStandardItem("level 2");



    And , then because everything are pointers, you can set items directly

  • Otherwise, maybe you want to set items by clicking on it .

    From the view ( treeview, listview...) get the the index by using the signals :
    @void clicked ( const QModelIndex & index )@

    Then, get the standardItem from the index and change it as you want !
    @QStandardItem * itemFromIndex ( const QModelIndex & index ) const@

  • If I understand correctly, there is no analog of QStandardItemModel::setItem() (which applies for tables) in the context of a tree structure. If I want to fully change an item at a given position in my tree, first I have to cut the branch beneath the parent (removeRow()) and second, graft there the new item (insertRow()). Am I wrong?

    Second thought: please forget, forgive or delete this post, the answers above are clear.

Log in to reply