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 allow the insite renaming of a QTreeWidgetItem

How to allow the insite renaming of a QTreeWidgetItem

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 5.4k 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.
  • J Offline
    J Offline
    j.lastra
    wrote on last edited by
    #1

    Hello:
    I have filled a QTreeView by code, inserting a collection of QTreeWidgetItem. I am inserting by code new items in the TReeView, and I need to create them in 'edition mode' to allow the user the renaming of the new node,
    such as is made by the 'new folder' command in Windows.

    I don´t how to do it, is it possible ? nad how to do it ?

    Regards,
    Juan

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You can simply call the edit function from QTreeWidget

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Don't mix QTreeView and QTreeWidgetItems. The latter should be used with QTreeWidget, not QTreeView.

        That being said, when you create a QTreeWidgetItem remember to "setFlags":http://qt-project.org/doc/qt-5/qtreewidgetitem.html#setFlags to contain Qt::ItemIsEditable (apart from the default ones) and then call "editItem":http://qt-project.org/doc/qt-5/qtreewidget.html#editItem

        1 Reply Last reply
        0
        • J Offline
          J Offline
          j.lastra
          wrote on last edited by Chris Kawa
          #4

          Thank you to Chris and Sgaist, but it doesn´t work. I show you my code below.
          After the editItem() call, the item's box doesn´t open.
          Moreover, whenever I make double-clicl on any item, the item doesn´t
          change to editing, such as any standard tree view in Windows.

           // We get the root node to insert a new palette
          
           usersPaletteRoot = ui.m_TreePalView->topLevelItem(1);
          
           // We create the novel palette entry
          
           newChild = new QTreeWidgetItem();
          
           newChild->setText(0, "New palette");
          
           newChild->setFlags(newChild->flags() | 
            Qt::ItemIsEditable | Qt::ItemIsEnabled
            | Qt::ItemIsSelectable);
          
           // We insert a new row in blank in the palette's list 
          
           usersPaletteRoot->addChild(newChild);
          
           disconnect(ui.m_TreePalView, SIGNAL(itemClicked(QTreeWidgetItem*, int)),
            this, SLOT(OnPaletteSelected(QTreeWidgetItem*, int)));
          
           newChild->setSelected(true);
          
           ui.m_TreePalView->editItem(newChild, 0);
          
          
          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            Just checked this:

            auto item = new QTreeWidgetItem(ui->treeWidget, QStringList {"Foo"});
            item->setFlags(item->flags() | Qt::ItemIsEditable);
            ui->treeWidget->editItem(item);
            

            Works as expected. Your code is similar so there's got to be some problem elsewhere.

            usersPaletteRoot = ui.m_TreePalView->topLevelItem(1);
            

            Is there always an element with index 1?

            1 Reply Last reply
            1

            • Login

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