I want to create as the following:
Unfortunately, Qt does not supported ready widget for that.
Is there is a plugin or any way to do that?
I want to create as the following:
Unfortunately, Qt does not supported ready widget for that.
Is there is a plugin or any way to do that?
Use QFileSystemModel on a QTreeView. If you look at the first of those two links, it actually contains example code doing exactly that.
would personally suggest not use QWidgets for this task if you can avoid it. Instead, try to utilize the new shiny QML way of building Qt UI. It might be only my personal opition, but QTreeView
has several flaws in my opinion.
Here you can find a simple example how it is done with QML these days. It is using the FolderListModel from Qt.labs.folderlistmodel 2.1
.
FolderListModel provides access to information about the contents of a folder in the local file system, exposing a list of files to views and other data components.
Note: This type is made available by importing the Qt.labs.folderlistmodel module. Elements in the Qt.labs module are not guaranteed to remain compatible in future versions.
import Qt.labs.folderlistmodel 2.1
The folder property specifies the folder to access. Information about the files and directories in the folder is supplied via the model's interface.
Should you insist on doing in C++ with the old QWidget
set, your choice is probably to use QTreeView as it is a tree view after all and then combine that with QFileSystemModel.
The code would be something like this:
QFileSystemModel *model = new QFileSystemModel;
model->setRootPath(QDir::currentPath());
QTreeView *tree = new QTreeView(splitter);
tree->setModel(model);
tree->setRootIndex(model->index(QDir::currentPath()));