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. How can i set QStandardItem in the row which have parents?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.8k 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.
  • R Offline
    R Offline
    Ruzik
    wrote on last edited by
    #1

    How can i set QStandardItem in the row which have parents?
    For example:
    !http://s1.hostingkartinok.com/uploads/images/2012/03/9aa311e5847fead3170fdb75eb69eec1.png(1)!

    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

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

      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");

      level1->appendRow(level2);
      level0->appendRow(level1);

      model->appendRow(level0);@

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

      Nothing in Biology Makes Sense Except in the Light of Evolution

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dridk
        wrote on last edited by
        #3

        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@

        Nothing in Biology Makes Sense Except in the Light of Evolution

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cypherluc
          wrote on last edited by
          #4

          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.

          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