Answer the question
In order to leave comments, you need to log in
QFileSystemModel, QTreeView: how to assign SIGNAL to specific file from tree?
Good afternoon. I'm trying to build a simple local help system in Qt: on the left - displaying the file system, on the right - displaying the contents of the file.
Code in main.cpp:
QFileSystemModel *model = new QFileSystemModel();
model->setRootPath(QDir::currentPath());
QTreeView *tree = new QTreeView();
tree->setModel(model);
tree->setRootIndex(model->index(QCoreApplication::applicationDirPath() + "/pkb_db")); // в этом каталоге - другие папки и файлы - "база"
layout1->addWidget(tree);
QModelIndex index1 = model->index(QCoreApplication::applicationDirPath() + "/pkb_db/Roadmaps/Roadmaps.html"); // назначаю индекс для определенного файла
QTextBrowser* center = new QTextBrowser;
layout2->addWidget(center);
center->setSource(QUrl("file:///" + QCoreApplication::applicationDirPath() + "/pkb_db/Roadmaps/Roadmaps.html"));
center->hide();
QObject::connect(tree, SIGNAL(clicked(const QModelIndex&)), center, SLOT(show()));
Answer the question
In order to leave comments, you need to log in
To find out what was clicked, you need a slot with the parameter const QModelIndex &model
And get the element like this QStandardItem *item = model->itemFromIndex(model->mapToSource(index));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question