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 to rename a child with only parent index known in a treeview ?
Forum Update on Monday, May 27th 2025

How to rename a child with only parent index known in a treeview ?

Scheduled Pinned Locked Moved Solved General and Desktop
qtreeviewindexparentchild
3 Posts 2 Posters 1.5k Views
  • 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.
  • RatzzR Offline
    RatzzR Offline
    Ratzz
    wrote on last edited by
    #1

    I am working on a QStandardItemModel with only the index of parent know how can i rename the child.
    I used setItem with parent row and column as 1 it returns 0

           Model->setItem(row,1,item);
    

    I even tried setData but it works only for parent

            ui->treeView->model()->setData(parentIndex,new_name,Qt::EditRole);
    

    How can i rename a child with only parent index known in a treeview?

    --Alles ist gut.

    kshegunovK 1 Reply Last reply
    0
    • RatzzR Ratzz

      I am working on a QStandardItemModel with only the index of parent know how can i rename the child.
      I used setItem with parent row and column as 1 it returns 0

             Model->setItem(row,1,item);
      

      I even tried setData but it works only for parent

              ui->treeView->model()->setData(parentIndex,new_name,Qt::EditRole);
      

      How can i rename a child with only parent index known in a treeview?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @Ratzz
      Hello,
      Retrieve the child model index first with QModelIndex::child and then set your data.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      RatzzR 1 Reply Last reply
      1
      • kshegunovK kshegunov

        @Ratzz
        Hello,
        Retrieve the child model index first with QModelIndex::child and then set your data.

        Kind regards.

        RatzzR Offline
        RatzzR Offline
        Ratzz
        wrote on last edited by
        #3

        @kshegunov
        Thanks for your reply.
        Yes retrieving the child model via child and then setting data worked for me .

        --Alles ist gut.

        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