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. [SOLVED] QTreeView subitem not being added correctly

[SOLVED] QTreeView subitem not being added correctly

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.1k Views 2 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.
  • K Offline
    K Offline
    kdev
    wrote on last edited by kdev
    #1

    Hi,
    I'm trying to add a subitem to the selected QTreeWidget item using the following code:

            QTreeWidgetItem *itm = new QTreeWidgetItem(this->ui->Defs_tree);
            itm->setText(0, name);
            if (subitem)
            {
                QList<QTreeWidgetItem *> lst = this->ui->Defs_tree->selectedItems();
                if ( lst.count() == 1 )
                    lst.at(0)->addChild(itm);
            } 
    

    But, the subitem gets added outside the selected item: and I'm still unable to solve the issue.
    I need some help.
    Thanks.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      The first line of your code puts the item into the tree already. Remove the tree parameter and you should be good to go. Be careful of leaking that item though, as you only seem to insert it conditionally.

      K 1 Reply Last reply
      1
      • Chris KawaC Chris Kawa

        The first line of your code puts the item into the tree already. Remove the tree parameter and you should be good to go. Be careful of leaking that item though, as you only seem to insert it conditionally.

        K Offline
        K Offline
        kdev
        wrote on last edited by
        #3

        @Chris-Kawa Yes, I missed that. Thanks a lot for your help.

        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