Results 1 to 2 of 2

Thread: QTableWidget vs QTableView and setSortRole

  1. #1
    Join Date
    Apr 2011
    Posts
    132
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    14

    Default QTableWidget vs QTableView and setSortRole

    I need to sort a table by different values that are displayed in the cells.

    The QTableView model has wonderful option to do it.

    Qt Code:
    1. model->setSortRole(Qt::UserRole);
    To copy to clipboard, switch view to plain text mode 

    But I do use QTableWidget and don't want to switch to TableView.

    What I can use to get it working in TableWidget instead ??

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: QTableWidget vs QTableView and setSortRole

    setSortRole() is a method of QStandardItemModel, not of any of the table view classes.
    ALso, since QTableWidget is derived from QTableView, QTableWidget IS a QTableView, and you wouldn't need to switch between classes.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 1
    Last Post: 26th November 2010, 12:06
  2. Replies: 0
    Last Post: 11th August 2010, 19:00
  3. Replies: 1
    Last Post: 10th June 2009, 21:59
  4. qtablewidget and qtableview
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 17th May 2008, 16:01
  5. QTableView versus QTableWidget
    By jcr in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2006, 19:51

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.