我有一个QTableView,其中有一个子类QSqlQueryModel和一个qsortfilterproxy模型。底层数据库中的某些列包含浮点数,它们按字符串的形式进行排序。示例:
-0.06
-1.45
0.02
0.05
...
使用Python/PyQt,我从this accepted answer实现了概述的解决方案,但它不起作用。在
我的子类QSqlQueryModel:
^{pr2}$设置代理:
proxy = QSortFilterProxyModel(self)
proxy.setSortRole(CatalogModel.SortRole)
我自己的SortRole没有出现在模型中,带有浮点数的列仍然像字符串一样排序。 为什么这个解决方案不起作用?我错过什么了吗?在
从latest official documentation:
实现您自己的sort()也可以是一个选项,但是:
可以按以下方式将-1传递给该方法:
^{pr2}$请注意,您在那里粘贴的两行没有分号。由于语法错误,代码甚至不能像那样编译。最好粘贴正确的代码。在
如果它不起作用,就实现你的排序。在
我想你需要打开分类开关。比如:
根据docshttp://doc.qt.io/qt-4.8/qsortfilterproxymodel.html列
-1
将打开底层模型的排序。这可能是你需要的。在相关问题 更多 >
编程相关推荐