PDA

View Full Version : How to use Tree view for activate different pages.



Braian
5th November 2012, 19:57
Hello, How can i do a menu with item from treeview ?

in the treeview object from QTreeview, i have the following items:

+CONFIGURATION
OPTION1
OPTION2
OPTION3

The three options are child items from parent item "configuration".

I want to show a different page with each OPTION.

For example, when i click over OPTION1, the pages related to OPTION2 and 3 hides, and shows OPTION1 Page.

How can i connect each item clicked to a different SLOT?

The escenario is: A Mainwindow created from new proyect, and the constructor of Mainwindow is:




MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QStandardItemModel *item_model = new QStandardItemModel;
QStandardItem *parent_item = new QStandardItem("CONFIGURATION");
QStandardItem *item1 = new QStandardItem("OPTION1");
QStandardItem *item2 = new QStandardItem("OPTION2");
QStandardItem *item3 = new QStandardItem("OPTION3");

ui->treeView->setModel(item_model);

parent_item->setChild(0,item1);
parent_item->setChild(1,item2);
parent_item->setChild(2,item3);
item_model->setItem(0,parent_item);
connect(ui->treeView,SIGNAL(clicked(QModelIndex)),ui->groupBox,SLOT(hide()));



}





All the items generates a signal and hide the groupbox, but... i want it only occurs when i click OPTION1 item only.

Thanks,

Braian

ChrisW67
5th November 2012, 22:54
You want a QStackedWidget to hold your pages. Then you connect the tree's clicked() signal to a slot that checks that it was a child item (not the parent) that was clicked before calling QStackedWidget::setCurrentIndex() with the row of the clicked item.

Very similar to the Config Dialog Example