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]How to read the items in QTreeWidget
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]How to read the items in QTreeWidget

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

    Hi everyone I am new to use QTreeWidget
    I can add, remove the items to QTreeWidget.

    I added the items like

    India-->Delhi,AndhraPradesh,TamilNadu
    USA-->Alaska,California,Georgia

    For reading the items I wrote a code like this

    @ QTreeWidgetItemIterator it(ui->treeWidget);
    while (*it) {
    ui->textEdit->append((*it)->text(0));
    ++it;
    }@

    Which gives the output like this...
    India
    Delhi
    AndhraPradesh
    TamilNadu
    USA
    Alaska
    California
    Georgia

    But my requirement is I want the country names in one QTextEdit and the States in other QTextEdit.
    How can we know that any item is having any children?
    Thank you.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      prabuqt
      wrote on last edited by
      #2

      Hi, I solved this problem by the following code.

      @void TreeTest::itemDoubleClicked(QTreeWidgetItem item, int column)
      {
      QList <QTreeWidgetItem
      >List;
      if(item->childCount()>0)
      {
      List = item->takeChildren();
      addToParentList(item,column);
      for(int idx=0; idx<List.length(); idx++)
      addToChildList(List.at(idx),column);

        }
          else
           addToParentList(item,column);
       delete item;
      

      }

      void TreeTest::addToParentList(QTreeWidgetItem *item, int column)
      {
      ui->textEdit->append(item->text(column));
      }
      void TreeTest::addToChildList(QTreeWidgetItem *item, int column)
      {
      ui->textEdit_1->append(item->text(column));
      }
      @

      Thank you.

      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