[英]How i can sort a list item by alphabetical order with QSortFilterProxyModel?
Hi i have set the QSortFilterProxyModel property in this mode您好我已在此模式下设置了 QSortFilterProxyModel 属性
int main(int argc, char *argv[])
{
....
ProgramFilterProxyModel programFPModel{};
programFPModel.setSourceModel(&pm);
engine.rootContext()->setContextProperty("programFPModel", &programFPModel);
....
}
ProgramFilterProxyModel::ProgramFilterProxyModel(QObject *parent) :
QSortFilterProxyModel(parent), m_stringaRicerca(""),
m_programListCurrIndex(0)
{
setSortRole(ProgramModel::NameQml);
setDynamicSortFilter(true);
sort(0);
setSortLocaleAware(true);
}
.... ……
When i execute my application on Ubuntu the item are correctly sort by alphabetical order because i have set isSortLocaleAware property on true, instead if i try to execute my application on embedded systems with buildroot OS(IMX6 microcontroller) the items aren't sort by alphabetical order.当我在 Ubuntu 上执行我的应用程序时,项目按字母顺序正确排序,因为我已将 isSortLocaleAware 属性设置为 true,而不是如果我尝试在具有 buildroot OS(IMX6 微控制器)的嵌入式系统上执行我的应用程序,项目不按字母顺序排序命令。
If i try to print with:如果我尝试使用以下方式打印:
qDebug()<< QLocale::system().language()
the locale of my buildroot OS the output is "C", instead on ubuntu is italian maybe is this the problem?我的 buildroot 操作系统的语言环境 output 是“C”,而不是 ubuntu 是意大利语可能是这个问题?
How i can sort the items by name and sort by alphabetical order without setSortLocaleAware(true)?我如何在没有 setSortLocaleAware(true) 的情况下按名称对项目进行排序并按字母顺序排序?
The order list that i want is the same sort order of a file list for example in ubuntu.我想要的顺序列表与文件列表的排序顺序相同,例如在 ubuntu 中。
Example:例子:
You may set your default locale (as soon as possible in your main())你可以设置你的默认语言环境(尽快在你的 main() 中)
QLocale::setDefault(QLocale(QLocale::Italian));
The above line is just an example.上面的行只是一个例子。 You should set a variable locale, depending on the user preferences, etc.
您应该根据用户偏好等设置变量区域设置。
Or you can overide the protected method bool QSortFilterProxyModel::lessThan()
and compare the items as you wish.或者您可以覆盖受保护的方法
bool QSortFilterProxyModel::lessThan()
并根据需要比较项目。 See the Custom Sort/Filter Model Example .请参阅自定义排序/过滤器 Model 示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.