QListView 根据模型的排序顺序显示不同大小的项目
我试图按名称、创建日期和上次访问日期对 QFileSystemModel 进行排序(全部升序和降序)。我使用 QSortFilterProxyModel 进行排序。不知何故,更改排序顺序时会产生奇怪的效果:在名称被省略之前显示的字符数变化很大。根据排序顺序,某些项目只有三个字母(Pro...),而其他项目则有多达十个字母(Programms)。我已经将视图网格大小设置得足够大(100x100),更改图标大小不会影响视图。
如果我直接对 QFileSystemModel 进行排序,一切都会正常,但我无法按文件名以外的其他方面进行排序。
在哪里可以更改 QSortFilterProxyModel 删除文本的行为?为什么我的代理会影响视图?我在哪里可以找到有关 QFileSystemModel 的更多信息?我仍然不知道其他列中存储了什么数据(#1 是文件名)。
屏幕截图:
如您所见,根据排序顺序,文件名会被省略或者它们不。如果我按降序排序,则为“twai...”,如果我按升序排序,则为“twain.dll”。
这就是当我单击排序箭头时执行的代码:
// 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);
}
提前致谢!
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 QFileSystemModel 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在
ItemDelegate
中,它将图标绘制到QListView
上。我对它进行了子类化,自己处理了省略和绘制,现在一切都按预期工作了。我将进一步调查这一点,并尽快(如果可以的话)发布详细的描述。The problem lies somewhere in the
ItemDelegate
which paints the icons onto theQListView
. 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.