[Q] Custom sorting of QListWidget items
-
Hello everybody,
I have following model of list view widget at the moment:Custom widget which i set to QListWidgetItem with icon and some labels
@
class GUIContactWidget : public QWidget
{
Q_OBJECTpublic:
explicit GUIContactWidget(QWidget *parent = 0);
~GUIContactWidget();QString skypename(); uint availability();
public slots:
void updateAvatar(const QPixmap &);
void updateSkypename(const QString &);
void updateFullname(const QString &);
void updateAvailability(uint );private:
Ui::GUIContactWidget *ui;
};
@here is how I use it with QListWidget.(this->ui->lv_contacts is QListWidget)
@
QListWidgetItem * item = new QListWidgetItem(this->ui->lv_contacts);
GUIContactWidget * conwidget = cons[i]->widget();
item->setSizeHint(conwidget->size());
this->ui->lv_contacts->setItemWidget(item,conwidget);
@GUIContactWidget is connected to QObject class from which it gets updates events for avatar, name and contact availability.
How can I implement easy and efficient(it's for ARM device) sorting for list view items using two parameters: availability and name(alphabetic sort) + resorting if this parameters are changed...for example like this:
Abcd(online)
Bcde(online)
....
Abcd(offline)
Bcde(offline) -
What about using QTableWidget and enabling "sorting multiple columns":http://qt-project.org/forums/viewthread/1349? Then you can add name and the availability using a column for each and then sort whatever you need. This way you could also sort by name only.
The other way was to have a QList<QString> that you can sort and fill into the listWidet each time something changes (using the strings in your example). This is possibly the easiest way.