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.
QFileSystemModel *TreeModel = new QFileSystemModel();
TreeModel->setRootPath("/Users/John/Documents");
tree.setModel(TreeModel);
QModelIndex idx
= TreeModel
->index
("/Users/John/Documents");
tree.setRootIndex(idx);
tree.show();
QFileSystemModel *TreeModel = new QFileSystemModel();
TreeModel->setRootPath("/Users/John/Documents");
QTreeView tree;
tree.setModel(TreeModel);
QModelIndex idx = TreeModel->index("/Users/John/Documents");
tree.setRootIndex(idx);
tree.show();
To copy to clipboard, switch view to plain text mode
For the mainwindow.cpp
MainWindow::MainWindow()
{
setCentralWidget(widget);
layout->addWidget(tree);
layout->addWidget(rightFiller);
widget->setLayout(layout);
MainWindow::MainWindow()
{
QWidget *widget = new QWidget;
setCentralWidget(widget);
QWidget *rightFiller = new QWidget;
rightFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QTreeView *tree = new QTreeView;
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(tree);
layout->addWidget(rightFiller);
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
MainWindow::MainWindow()
setCentralWidget(widget);
QFileSystemModel *TreeModel = new QFileSystemModel();
TreeModel->setRootPath("/Users/John/Documents");
QModelIndex idx
= TreeModel
->index
("/Users/John/Documents");
tree->setModel(TreeModel);
tree->setRootIndex(idx);
layout->addWidget(tree);
layout->addWidget(rightFiller);
widget->setLayout(layout);
MainWindow::MainWindow()
QWidget *widget = new QWidget;
setCentralWidget(widget);
QWidget *rightFiller = new QWidget
rightFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QFileSystemModel *TreeModel = new QFileSystemModel();
TreeModel->setRootPath("/Users/John/Documents");
QModelIndex idx = TreeModel->index("/Users/John/Documents");
QTreeView *tree = new QTreeView;
tree->setModel(TreeModel);
tree->setRootIndex(idx);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(tree);
layout->addWidget(rightFiller);
widget->setLayout(layout);
To copy to clipboard, switch view to plain text mode
Will probably be back soon enough asking for more help
Bookmarks