Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Q] Custom sorting of QListWidget items
Forum Updated to NodeBB v4.3 + New Features

[Q] Custom sorting of QListWidget items

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AcerExtensa
    wrote on last edited by
    #1

    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_OBJECT

    public:
    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)

    God is Real unless explicitly declared as Integer.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      franku
      wrote on last edited by
      #2

      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.

      This, Jen, is the internet.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved