QListView displays different sized items depending on sort order of model
Im trying to sort a QFileSystemModel by name, date of creation and date of last access (all ascending and descending). Im using QSortFilterProxyModel for sorting. Somehow there is a strange effect when changing sort order: The number of characters displayed until the name gets elided varies very strong. Depending on the sort order, some items have only three letters (Pro...) while others have up to ten (Programms). I already set the views grid size big enough (100x100), changing the icon size doesnt affect the view.
If I sort the QFileSystemModel directly everything works fine, but I cant sort by other aspects than filename then.
Where can I change the behavior how QSortFilterProxyModel elides text? Why does my proxy affect the view at all? Where can I find any further information about the QFil开发者_开发百科eSystemModel at all? I still dont know what data is stored in the other columns (#1 is filename).
Screenshot:
As you can see, depending on the sortorder, filenames get elided or they don't. If im sorting descending, its "twai...", if im sorting ascending its "twain.dll".
Thats the code which gets executed when I click the sort arrow:
// initialization
fileNameSortModel = new QSortFilterProxyModel(parent);
fileNameSortModel.sourceModel(originalModel); // originalModel is type of QFileSystemModel
// ...
void PFileListWithHeader::onNameSort(Qt::SortOrder order)
{
currentModel = fileNameSortModel;
view->setModel(currentModel);
view->setRootIndex(translateOriginalIndexToProxy(originalModel->index(path)));
currentModel->sort(0, order);
}
Thanks in advance!
The problem lies somewhere in the ItemDelegate
which paints the icons onto the QListView
. I subclassed it, handled eliding and painting myself and now everything works as it should. I will investigate this furter and post a detailled description as soon as (and if) I can.
精彩评论