문제

I have issues while using sortItems() on a QListWidget. Here is what happens:

Changes this:

A z d C E o I

to this:

A C I d e o z

But i want it to be:

A C d e I o z

Any way to change to make it sort like that?

도움이 되었습니까?

해결책

QListWidget uses the DisplayRole (the item's text) for sorting and calls QString::localeAwareCompare on them. To override the default, you can either change the locale used (see QLocale) or have your own QListWidgetItem subclass reimplementing QListWidgetItem::operator< and let it do the comparison you want.

For anything more advanced, I'd suggest to have a look at QListView, which you could combine either with your own model implementation or the convenience models QStandardItemModel or QStringListModel (the latter could be the most simple and elegant solution in your case). For sorting, you would then put a QSortFilterProxyModel in between the actual model and the view.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top