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 make Toolbar to Expand the Qtreeview in DOM?
Forum Updated to NodeBB v4.3 + New Features

How to make Toolbar to Expand the Qtreeview in DOM?

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

    Screenshot (233).png
    I want to Add another toolbar Icon next to the first one.
    The First Icon loads the XML file into Treeview

    QToolBar *fileToolBar = addToolBar(tr("FIND"));
         const QIcon newIcon = QIcon::fromTheme("FIND", QIcon("Image\\FIND.png"));
         QAction *newAct = new QAction(newIcon, tr("&FIND"), this);
         newAct->setShortcuts(QKeySequence::Open);
         connect(newAct, &QAction::triggered, this, &MainWindow::openFile);
         fileToolBar->addAction(newAct);
    

    I want that Second tool item Expands the Treeview.
    So far I have tried:
    But It didn't worked!

         QToolBar *ExpandToolBar = addToolBar(tr("Expand"));
         const QIcon newIcon2 = QIcon::fromTheme("Expand", QIcon("\Image\\Expand.png"));
         QAction *newAct2 = new QAction(newIcon2, tr("&Expand"), this);
         newAct2->setShortcuts(QKeySequence::SelectStartOfLine);
         connect(newAct2, &QAction::isVisible, this, &MainWindow::expandChildren);
         ExpandToolBar->addAction(newAct2);
    

    Where expandChildren Function is as Follow:

    void MainWindow::expandChildren(const QModelIndex &index, QTreeView *view)
    {
        if (!index.isValid()) {
            return;
        }
    
        int childItem = index.model()->rowCount(index);
        for (int i = 0; i < childItem; i++) {
            const QModelIndex &child = index.sibling(i, 0);
            // Recursively call the function for each child node.
            expandChildren(child, view);
        }
    
        if (!view->isExpanded(index)) {
            view->expand(index);
        }
    }
    

    In the Image I have shown Where I want that Icon.

    M 1 Reply Last reply
    0
    • Aviral 0A Aviral 0

      Screenshot (233).png
      I want to Add another toolbar Icon next to the first one.
      The First Icon loads the XML file into Treeview

      QToolBar *fileToolBar = addToolBar(tr("FIND"));
           const QIcon newIcon = QIcon::fromTheme("FIND", QIcon("Image\\FIND.png"));
           QAction *newAct = new QAction(newIcon, tr("&FIND"), this);
           newAct->setShortcuts(QKeySequence::Open);
           connect(newAct, &QAction::triggered, this, &MainWindow::openFile);
           fileToolBar->addAction(newAct);
      

      I want that Second tool item Expands the Treeview.
      So far I have tried:
      But It didn't worked!

           QToolBar *ExpandToolBar = addToolBar(tr("Expand"));
           const QIcon newIcon2 = QIcon::fromTheme("Expand", QIcon("\Image\\Expand.png"));
           QAction *newAct2 = new QAction(newIcon2, tr("&Expand"), this);
           newAct2->setShortcuts(QKeySequence::SelectStartOfLine);
           connect(newAct2, &QAction::isVisible, this, &MainWindow::expandChildren);
           ExpandToolBar->addAction(newAct2);
      

      Where expandChildren Function is as Follow:

      void MainWindow::expandChildren(const QModelIndex &index, QTreeView *view)
      {
          if (!index.isValid()) {
              return;
          }
      
          int childItem = index.model()->rowCount(index);
          for (int i = 0; i < childItem; i++) {
              const QModelIndex &child = index.sibling(i, 0);
              // Recursively call the function for each child node.
              expandChildren(child, view);
          }
      
          if (!view->isExpanded(index)) {
              view->expand(index);
          }
      }
      

      In the Image I have shown Where I want that Icon.

      M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      @Aviral-0 said in How to make Toolbar to Expand the Qtreeview in DOM?:

      QToolBar *fileToolBar = addToolBar(tr("FIND"));
      QToolBar *ExpandToolBar = addToolBar(tr("Expand"));

      You create a new toolbar each time, you only need one.

      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