What determines file sorting in QFileDialog?

Users open files in our application through QFileDialog. The file name order is fancy. What determines the sort order and how can we sort it by file name or otherwise impose our own sort, possibly indicating its own comparison function?

Documentation and online forums did not help. If it is not hidden, there is no sorting method, property, etc.

This is the main application for Linux, but also works on Mac computers. (I don't know anything about the Mac.)

Here is the juicy part of the source code:

QtFileDialog chooser(parent, caption, directory, filter);
/// QtFileDialog is our class derived from QFileDialog

chooser.setModal(true);
chooser.setAcceptMode(acceptMode);
chooser.setFileMode(fileMode);

QStringList hist = chooser.history();
chooser.setHistory(hist);

/* point "x" */

if(chooser.exec()) {    
    QStringList files = chooser.selectedFiles();
    ...blah blah blah...

From one of the answers, I tried an evil experiment by adding this poorly informed guess code to "point x":

QSortFilterProxyModel *sorter = new QSortFilterProxyModel();
sorter->sort(1);  // ???
chooser.setProxyModel(sorter);

33 , . , Qt4 , QSortFilterProxyModel.

+5
3

QFileDialog, exec()? , . , , . , , setViewMode(QFileDialog::Detail) exec().

QFileDialog::getOpenFileName(), , , . .

1:

OP: alt text

. , Qt , Windows XP, .

. , :

A_A_10e0
A_A_9a05

, 1 9.

.. ( Windows 7, ), :

A_A_9a05
A_A_10e0

9 10.

, , , , . , , Qt , .

2:

QSortFilterProxyModel , , , . , " x" .. ( :)

QSortFilterProxyModel *sorter = new QSortFilterProxyModel();
sorter->setDynamicSortFilter(true); // This ensures the proxy will resort when the model changes
chooser.setProxyModel(sorter);
+4

, QSortFilterProxyModel, QFileDialog QFileDialog:: setProxyModel (QAbstractProxyModel * proxyModel)

Qt 4.6.

http://doc.trolltech.com/4.6/qfiledialog.html#setProxyModel

http://doc.trolltech.com/4.6/qsortfilterproxymodel.html#details

+2

, Qt... .

, Windows,

QFileDialog, Name, . , . , MS- Word, Name ..

, ...

Windows , . , , , , ... , , MS-Word...

So, I suppose it depends on the implementation of Native OS, and not on QFileDialog...

0
source

All Articles