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 create a new QTreeWidgetItem and then input its name in the created item?
Forum Updated to NodeBB v4.3 + New Features

how can i create a new QTreeWidgetItem and then input its name in the created item?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 857 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.
  • O Offline
    O Offline
    opengpu2
    wrote on last edited by
    #1

    how can i create a new QTreeWidgetItem and then input its name in the created item?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      you have to make the Item Editable

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • O Offline
        O Offline
        opengpu2
        wrote on last edited by
        #3

        void TreeEdit::addNode()
        {
        QTreeWidgetItem *curItem=m_tree->currentItem();
        QTreeWidgetItem *newItem=new QTreeWidgetItem(curItem);

        curItem->addChild(newItem);  
        
        QLineEdit *lineEdit=new QLineEdit(this);  
        connect(lineEdit,SIGNAL(editingFinished()),this,SLOT(finishEdit()));  
        
        m_tree->setItemWidget(newItem,0,lineEdit);  
        m_tree->expandItem(curItem);  
        
        m_tree->setCurrentItem(newItem);  
        
        lineEdit->setText("default");  
        lineEdit->setSelection(0,7);  
        

        }

        void TreeEdit::finishEdit()
        {
        QTreeWidgetItem *curItem=m_tree->currentItem();
        QLineEdit edit=qobject_cast<QLineEdit>(m_tree->itemWidget(curItem,0));
        if(!edit)
        return;

        QString text=edit->text();  
        
        m_tree->removeItemWidget(curItem,0);  
        
        curItem->setText(0,text);  
        

        }

        1 Reply Last reply
        0
        • O Offline
          O Offline
          opengpu2
          wrote on last edited by
          #4

          is there any better way to do this?

          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