QListView 根据模型的排序顺序显示不同大小的项目

发布于 2024-10-06 07:52:02 字数 1104 浏览 0 评论 0原文

我试图按名称、创建日期和上次访问日期对 QFileSystemModel 进行排序(全部升序和降序)。我使用 QSortFilterProxyModel 进行排序。不知何故,更改排序顺序时会产生奇怪的效果:在名称被省略之前显示的字符数变化很大。根据排序顺序,某些项目只有三个字母(Pro...),而其他项目则有多达十个字母(Programms)。我已经将视图网格大小设置得足够大(100x100),更改图标大小不会影响视图。

如果我直接对 QFileSystemModel 进行排序,一切都会正常,但我无法按文件名以外的其他方面进行排序。

在哪里可以更改 QSortFilterProxyModel 删除文本的行为?为什么我的代理会影响视图?我在哪里可以找到有关 QFileSystemModel 的更多信息?我仍然不知道其他列中存储了什么数据(#1 是文件名)。

屏幕截图:

alt text

如您所见,根据排序顺序,文件名会被省略或者它们不。如果我按降序排序,则为“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:

alt text

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对不⑦ 2024-10-13 07:52:02

问题出在 ItemDelegate 中,它将图标绘制到 QListView 上。我对它进行了子类化,自己处理了省略和绘制,现在一切都按预期工作了。我将进一步调查这一点,并尽快(如果可以的话)发布详细的描述。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文