QTreeView with QFileSystemModel not sorting



  • Hi,
    I have a QTreeView for a QFileSystemModel in which I only keep the Name column visible.

    I have set

    m_dirTree->setSortingEnabled(true);
    m_dirTree->sortByColumn(index.column(), Qt::AscendingOrder);
    

    and use the following to add a subfolder to the currently selected folder:

    index = m_treeModel->mkdir(index, foldername);
    

    The view is updated to show the newly added folder, but it is appended at the end of the subdir list. So even if I name my new folder AA, it will still show after ZZZ.

    Forcing a sort by clicking on the header's sort arrow does not correct this either?
    What is going on?



  • QObject::connect(m_treeModel,&QAbstractItemModel::dataChanged,[=]()->void {m_treeModel->sort(0);});



  • @VRonin said in QTreeView with QFileSystemModel not sorting:

    QObject::connect(m_treeModel,&QAbstractItemModel::dataChanged,=->void {m_treeModel->sort(0);});

    Thanks @VRonin .

    I tried you connect, and the slot is called, but the sort has no effect.

    The thing is, when I create the AA folder manually in Explorer, the tree updates correctly and shows AA at the top. So maybe I should try using another method to make the directory than

    QFileSysModel::mkdir()
    

    Indeed, when I use QDir::mkdirI() the model updates to the correct sort order...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.