QFileSystemModel + QTreeView doesn't sort
Unsolved
General and Desktop
-
Hello,
i used the Qt example dirview to get an idea to use QFileSystemModel.
c:\Qt\Examples\Qt-5.12.1\widgets\itemviews\dirview\I created a new QWidgets application and add a QTreeView to the mainwindow.ui.
Thats all i changed in the ui.add in mainwindow.h
QFileSystemModel *model;
and my mainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); model = new QFileSystemModel(this); model->setRootPath( QString("C:/") ); model->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs); ui->treeView->setModel(model); // Settings TreeView ui->treeView->setAnimated(false); ui->treeView->setIndentation(20); ui->treeView->setSortingEnabled(true); ui->treeView->sortByColumn(0, Qt::AscendingOrder); ui->treeView->setWindowTitle(QObject::tr("Explorer")); } MainWindow::~MainWindow() { delete ui; }
The code is nearly the same as from the example.
BUT the example is sorting all columns, my code not.
I disabled all code lines from the example that belong to QCommandLineParser
and QModelIndex, in that case it is nearly the same code as my own code and the example sorts (!!).
I have no idea why not. Can anyone help?
Regards