How to make Toolbar to Expand the Qtreeview in DOM?
-
I want to Add another toolbar Icon next to the first one.
The First Icon loads the XML file into TreeviewQToolBar *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.
-
I want to Add another toolbar Icon next to the first one.
The First Icon loads the XML file into TreeviewQToolBar *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.