Results 1 to 1 of 1

Thread: Main Window Layout treeview item

  1. #1
    Join Date
    Mar 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Main Window Layout treeview item

    Hi folks

    I am having a bit of difficulty trying to get a treeview model to appear on my main window. I can get a blank treeview to appear but I want it to be used as a file directory and do not know how to link the blank treeview in my window to my directory model.

    I can create a suitable file directory on it's own dialogue box but I'm struggling to get it to link with my blank treeview in the main page.

    This is the code I use for making the working treeview directory in it's own dialogue box in the main.cpp.

    Qt Code:
    1. QFileSystemModel *TreeModel = new QFileSystemModel();
    2. TreeModel->setRootPath("/Users/John/Documents");
    3. QTreeView tree;
    4. tree.setModel(TreeModel);
    5. QModelIndex idx = TreeModel->index("/Users/John/Documents");
    6. tree.setRootIndex(idx);
    7. tree.show();
    To copy to clipboard, switch view to plain text mode 

    For the mainwindow.cpp

    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3.  
    4. QWidget *widget = new QWidget;
    5. setCentralWidget(widget);
    6.  
    7. QWidget *rightFiller = new QWidget;
    8. rightFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    9.  
    10. QTreeView *tree = new QTreeView;
    11.  
    12.  
    13. QHBoxLayout *layout = new QHBoxLayout;
    14.  
    15. layout->addWidget(tree);
    16. layout->addWidget(rightFiller);
    17. widget->setLayout(layout);
    To copy to clipboard, switch view to plain text mode 

    Any advice would be greatly appreciated in helping me get this sorted


    Added after 38 minutes:


    Got it working. The mainwindow.cpp now looks like

    Qt Code:
    1. MainWindow::MainWindow()
    2.  
    3. QWidget *widget = new QWidget;
    4. setCentralWidget(widget);
    5.  
    6. QWidget *rightFiller = new QWidget
    7. rightFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    8.  
    9. QFileSystemModel *TreeModel = new QFileSystemModel();
    10. TreeModel->setRootPath("/Users/John/Documents");
    11. QModelIndex idx = TreeModel->index("/Users/John/Documents");
    12.  
    13. QTreeView *tree = new QTreeView;
    14. tree->setModel(TreeModel);
    15. tree->setRootIndex(idx);
    16.  
    17. QHBoxLayout *layout = new QHBoxLayout;
    18. layout->addWidget(tree);
    19. layout->addWidget(rightFiller);
    20. widget->setLayout(layout);
    To copy to clipboard, switch view to plain text mode 

    Will probably be back soon enough asking for more help
    Last edited by qwerty1234; 30th March 2011 at 15:41.

Similar Threads

  1. Replies: 2
    Last Post: 17th February 2011, 12:30
  2. Hiding Layout item - Layout does not use available space
    By Asperamanca in forum Qt Programming
    Replies: 0
    Last Post: 27th January 2011, 09:51
  3. Auto Layout TreeView's item?
    By jerry7 in forum Qt Programming
    Replies: 3
    Last Post: 21st September 2010, 06:48
  4. Replies: 11
    Last Post: 11th August 2008, 09:14
  5. Replies: 15
    Last Post: 23rd March 2007, 16:16

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.