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] Qt5.2 How to expand all child items in Qtreewidget?

[SOLVED] Qt5.2 How to expand all child items in Qtreewidget?

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

    Hi, I have the following code:

    @void MainWindow::AddRoot (QString name)
    {
    QTreeWidgetItem *itm = new QTreeWidgetItem(ui->treeWidget);
    itm->setText(0,name);

    AddChild(itm, tr("Name"));
    AddChild(itm, tr("Address"));
    AddChild(itm, tr("Tel"));
    

    }

    void MainWindow::AddChild (QTreeWidgetItem *parent, QString name)
    {
    QTreeWidgetItem *itm = new QTreeWidgetItem();
    itm->setText(0,name);
    parent->addChild(itm);

    } @

    How do i make the child items under the parent level expand/collapse by default on run time?

    qxoz: for future, please add code tags for code

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      Have you try "setExpanded":http://qt-project.org/doc/qt-5/qtreewidgetitem.html#setExpanded ?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sharon_obl82
        wrote on last edited by
        #3

        yes I looked into it but I'm not quite sure how to use it. do you have an example code? thx

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          @void MainWindow::AddRoot (QString name)
          {
          QTreeWidgetItem *itm = new QTreeWidgetItem(ui->treeWidget);
          itm->setText(0,name);

          AddChild(itm, tr("Name"));
          AddChild(itm, tr("Address"));
          AddChild(itm, tr("Tel"));
          itm->setExpanded(true);
          

          }@

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sharon_obl82
            wrote on last edited by
            #5

            Thanks @qxoz ! it works!

            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