Results 1 to 2 of 2

Thread: QTableWidgte, sort by CheckBox column

  1. #1
    Join Date
    Jun 2014
    Posts
    8
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default QTableWidgte, sort by CheckBox column

    Hello everyone,
    I have QTableWidget with enabled sorting(clikck ti header) and last column with CheckStateRole.
    The problem is that sortin by column with CheckState doesnt work. Also I tried use QCheckBox widgets and delegate for cells.
    If anybody have a advice how to sort it, I would appreciate.

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

    Default Re: QTableWidgte, sort by CheckBox column

    Sorting by the column with a a checkbox does work but it sorts based on the content of the cell's DisplayRole, probably nothing in your case, not the check state.

    You should use QTableView and a separate model. If you want the model to sort on a different role, order or whatever, then you should reimplement its QAbstractItemModel::sort() function. If you use a QStandardItemModel then you can use QStandardItemModel::setSortRole() instead.

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

    Asting (6th November 2014)

Similar Threads

  1. A checkbox only column in QTableView
    By gfernandes in forum Newbie
    Replies: 3
    Last Post: 28th January 2014, 17:55
  2. Replies: 0
    Last Post: 25th June 2013, 14:49
  3. How does the QTableWidget sort a column?
    By codemonkey in forum Qt Programming
    Replies: 1
    Last Post: 4th October 2009, 13:21
  4. Replies: 1
    Last Post: 6th July 2009, 01:53
  5. Replies: 2
    Last Post: 20th August 2008, 15:55

Tags for this Thread

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.