Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.1.0
-
None
Description
Here's the code:
#include <QtWidgets> class Form : public QWidget { Q_OBJECT public: Form(QWidget *parent = nullptr) : QWidget(parent) { auto grid = new QGridLayout(this); auto list = new QListView; auto test = new QPushButton("Test Me"); auto path = new QLineEdit("D:/test"); grid->addWidget(list, 1, 0, 1, 3); grid->addWidget(test, 0, 2, 1, 1); grid->addWidget(path, 0, 0, 1, 2); auto model = new QFileSystemModel; model->setIconProvider(new QFileIconProvider); model->setFilter(QDir::Files); list->setModel(model); list->setRootIndex(model->setRootPath("D:/test")); connect(test, &QPushButton::clicked, [model, path, list] () { list->setRootIndex(model->setRootPath(path->text())); }); } }; //------------------------------------------------------------------------------ int main(int argc, char *argv[]) { QApplication a(argc, argv); Form w; w.resize(400, 400); w.show(); return a.exec(); }
I've created a class Form for testing this situation. When I am pressing the "Test Me" button, then form must show files in path given from the QLineEdit element. First I watch files in D:/Test directory, the list shows files in it, then go to D:/ and the list shows last opened Test directory. And if we go to D:/Home dir, and then again to D:/ list will show both Test and Home dirs. Though the filter is QDir::Files only, and it doesn't show any other folders in D:/.