Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Qt - Sort method does not update view - QTreeView and QAbstractItemModel

$
0
0
Hi, This question has been posted multiple times, but none of the answers provided could help me. Hence posting it again. I have a QTreeView and a QAbstractItemModel up and working (Source code copied from Your text to link here… [github.com] ). The below program is expected to do a directory listing along with file/folder creation date, size etc. I recently introduced the sorting function, to sort the file/folder names. The problem is, sorting works fine only for the first level of root items in the hierarchy, but suppose if I expand a Folder, and then click on the sort indicator (on the 0th column), things gets messed up. The view does not show correct values. I added some prints in the sort function to see, if the function is just sorting (re-arranging) or doing any copying or insertion or deletion. Luckily the sort function does not re-inset or copy or delete, it just re-arranges (as far as I understood). As explained in other posts, I tried calling emit dataChange(index, index), tried emit layoutabouttobechanged/layoutchanged rest model etc. But none of the things could work fine. One thing I doubt is either the indexes are getting corrupted or I am not updating the view with the right signals. All I expect is when I expand some of the Folders and then click sort, the view must display properly with sorted values and leave the expanded Folders still intact. Please help me out what I am missing. Important note, I added couple of lines in main.cpp to enable sorting. Snippet as below FtpWindow(QWidget *parent = 0) : QWidget(parent) {         ui.setupUi(this);         ui.leftView->setModel(&dirModel);         ui.rightView->setModel(&ftpModel);         ui.rightView->setSortingEnabled(true);         ui.rightView->sortByColumn(0, Qt::AscendingOrder);         ui.rightView->setAcceptDrops(true);         ui.host->setText("localhost");         connect(ui.leftUrl, SIGNAL(textChanged(const QString& )),                 this, SLOT(leftPathChanged(const QString &)));         connect(ui.connectButton, SIGNAL(clicked()), this, SLOT(connectToHost()));         connect(ui.refreshButton, SIGNAL(clicked()), this, SLOT(refresh()));     } Thanks, -Sandeep

Viewing all articles
Browse latest Browse all 13965

Trending Articles