View Full Version : Implementing QListWidget sortItems
Superwig
1st June 2015, 12:38
Hi, I'm wondering how to go about implementing QListWidget::sortItems() based on different data in my custom QListWidgetItem.
For example, to be able to call sortItems(Type::ID) or sortItems(Type::Name) with both ascending and decending option but I'm having trouble figuring out how to go about doing that.
On a related note, I can't seem to find a method for getting all the QListWidgetItems in QListWidget, how would one go about getting a list of the items? Just create a basic for loop and call QListWidget::Item?
wysota
1st June 2015, 13:21
Hi, I'm wondering how to go about implementing QListWidget::sortItems() based on different data in my custom QListWidgetItem.
For example, to be able to call sortItems(Type::ID) or sortItems(Type::Name) with both ascending and decending option but I'm having trouble figuring out how to go about doing that.
What is the problem you are having?
On a related note, I can't seem to find a method for getting all the QListWidgetItems in QListWidget, how would one go about getting a list of the items? Just create a basic for loop and call QListWidget::Item?
QListWidget::item() returns a given item, QListWidget::count() returns the number of items.
Superwig
1st June 2015, 14:12
How to reimplement sortItems
anda_skoa
1st June 2015, 16:54
When you call sortItems(), the list view will run a sorting algorthm on its items, using the items' operator<() for comparison.
So you decide which item "is less than" another by reiplementing that operator.
Cheers,
_
Superwig
1st June 2015, 17:29
When you call sortItems(), the list view will run a sorting algorthm on its items, using the items' operator<() for comparison.
So you decide which item "is less than" another by reiplementing that operator.
Cheers,
_
So how would you go about implementing a sort function on the items which takes a parameter?
wysota
1st June 2015, 18:07
You would check the current settings of the list widget owning the item and act upon that.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.