[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

    explicit GUIContactWidget(QWidget *parent = 0);

    QString skypename();
    uint availability();

    public slots:
    void updateAvatar(const QPixmap &);
    void updateSkypename(const QString &);
    void updateFullname(const QString &);
    void updateAvailability(uint );

    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();

    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:

  • 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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.