Results 1 to 2 of 2

Thread: Sorting on a model with multiple strings in items

  1. #1
    Join Date
    Mar 2010
    Posts
    22
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Symbian S60

    Question Sorting on a model with multiple strings in items

    Hi

    I have a model where for each item I have Multiple Text Strings for display. Sortingdoesn't seem to work when I have multiple Strings. But works when i have a single String.

    Here is my Code:

    QStringList data;
    QStandardItem *item = new QStandardItem();
    data.clear();
    data << "ABC" << "DEF" ;
    item->setData(QVariant(data), Qt:isplayRole);
    MyStandardModel->insertRow(0);
    MyStandardModel->setItem(0,item);
    StandardModel->sort(0,Qt::AscendingOrder);

    So here Sorting doesn't work on Model, but if I change:
    data << "ABC" << "DEF" ; to data << "ABC" ;
    Sorting Works.

    Same is the Case while Filtering using Sort FilterproxyModel Applied on it.

    Could someone please tell me where am I going wrong or the changes I need to make to sort()

    Thanks

  2. #2
    Join Date
    Mar 2010
    Posts
    69
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sorting on a model with multiple strings in items

    Subclass QAbstractListModel class. And than re-implement

    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
    virtual QVariant data(const QModelIndex &index, int role) const;

    It will make your work easier.

    Hope this will help.

Similar Threads

  1. Sorting Combobox Items
    By raphaelf in forum Newbie
    Replies: 5
    Last Post: 23rd June 2008, 09:00
  2. QTableView sorting when using a model
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2008, 14:13
  3. Model sorting vs. selection
    By VlJE in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 17:46
  4. QTableWidget Sorting Multiple Selection
    By rhiacasta in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2006, 22:05
  5. Sorting Tree items based on database properties
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 13th April 2006, 20:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.