Results 1 to 2 of 2

Thread: How to use Tree view for activate different pages.

  1. #1
    Join Date
    Dec 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default How to use Tree view for activate different pages.

    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:


    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. QStandardItem *parent_item = new QStandardItem("CONFIGURATION");
    7. QStandardItem *item1 = new QStandardItem("OPTION1");
    8. QStandardItem *item2 = new QStandardItem("OPTION2");
    9. QStandardItem *item3 = new QStandardItem("OPTION3");
    10.  
    11. ui->treeView->setModel(item_model);
    12.  
    13. parent_item->setChild(0,item1);
    14. parent_item->setChild(1,item2);
    15. parent_item->setChild(2,item3);
    16. item_model->setItem(0,parent_item);
    17. connect(ui->treeView,SIGNAL(clicked(QModelIndex)),ui->groupBox,SLOT(hide()));
    18.  
    19.  
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 

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

    Thanks,

    Braian

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to use Tree view for activate different pages.

    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

Similar Threads

  1. table view and tree view
    By MKSPulok in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2012, 22:48
  2. Replies: 8
    Last Post: 6th May 2010, 12:17
  3. Tree View
    By bismitapadhy in forum Qt Programming
    Replies: 1
    Last Post: 8th June 2009, 07:31
  4. C++ Tree View operation
    By zeeb100 in forum Qt Programming
    Replies: 9
    Last Post: 18th February 2009, 18:09
  5. tree view!!
    By Seema Rao in forum Qt Programming
    Replies: 4
    Last Post: 9th May 2006, 15:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.