Results 1 to 13 of 13

Thread: QTableView sorting

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2010
    Location
    Earth
    Posts
    50
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3

    Default Re: QTableView sorting

    Quote Originally Posted by ChrisW67 View Post
    So create the item with the default constructor and then use QStandardItem::setData() to set a QVariant of type QVariant::Int (or Uint, LongLong etc.) as the data for the Qt:isplayRole.
    Ok, this works!

    Qt Code:
    1. item->setData(QVariant(12345), Qt::DisplayRole);
    2. column5.append(item);
    To copy to clipboard, switch view to plain text mode 


    Quote Originally Posted by ChrisW67 View Post
    Alternatively, set the integer data on the EditRole and use setSortRole on the model to set the sort role to the EditRole.
    How can I do this? Have you a code snippet for me?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: QTableView sorting

    If setting the Qt::DisplayRole is working then just use that. However:
    Qt Code:
    1. item->setData(QVariant(12345), Qt::EditRole);
    2. column5.append(item);
    To copy to clipboard, switch view to plain text mode 
    and, elsewhere:
    Qt Code:
    1. model->setSortRole(Qt::EditRole);
    To copy to clipboard, switch view to plain text mode 
    This makes all the columns in the model sort on the edit role.

  3. The following user says thank you to ChrisW67 for this useful post:

    realdarkman71 (1st December 2010)

  4. #3
    Join Date
    Oct 2010
    Location
    Earth
    Posts
    50
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3

    Default Re: QTableView sorting

    Ok, big thanks for your help!

Similar Threads

  1. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 18:13
  2. QTableView sorting problem
    By noktus in forum Newbie
    Replies: 11
    Last Post: 23rd April 2008, 11:20
  3. QSqlTableModel and QTableView and sorting
    By JeanC in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2008, 14:22
  4. QTableView sorting
    By Bojan in forum Newbie
    Replies: 2
    Last Post: 28th September 2006, 09:11
  5. Sorting QTableView
    By Jimmy2775 in forum Qt Programming
    Replies: 7
    Last Post: 9th February 2006, 17:47

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
  •  
Qt is a trademark of The Qt Company.