Results 1 to 20 of 21

Thread: QTableWidget case sensitive sort

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Posts
    60
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget case sensitive sort

    Thanks a lot for your reply.

    I have implemented this. and working fine.

    can anyone help me to sort all other item except the first item ( I am having '..' as the first item).

    after sorting, it is stayed in the first. but
    problem is:
    when the sorted column is again clicked, this comes to the bottom.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget case sensitive sort

    Quote Originally Posted by jay View Post
    Thanks a lot for your reply.

    I have implemented this. and working fine.

    can anyone help me to sort all other item except the first item ( I am having '..' as the first item).

    after sorting, it is stayed in the first. but
    problem is:
    when the sorted column is again clicked, this comes to the bottom.
    For item '..' operator < must always return true

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget case sensitive sort

    No, if the sort order is reversed, it has to be the greatest item of all, so it has to return false. I think it's best to reimplement QTableWidget::sortItems().

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget case sensitive sort

    I guess QTableWidget::sortItems() is not virtual, and cant be reimplemented , isnt it ??

    Also for sorting icons, one can associate some role with the item and do sorting based on that role for the icon.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget case sensitive sort

    Quote Originally Posted by aamer4yu View Post
    I guess QTableWidget::sortItems() is not virtual, and cant be reimplemented , isnt it ??
    Hmm... right. Somehow I was sure there was a "virtual" keyword when I checked the method before posting. Anyway, knowing the item, you can ask it for its QTableWidgetItem::tableWidget() which then can be asked for its QTableWidget::horizontalHeader() which in turn can be asked for QHeaderView::sortIndicatorOrder() and QHeaderView::sortIndicatorSection(). Based on that info you can implement the sorting function in the item.

  6. #6
    Join Date
    Feb 2008
    Posts
    60
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget case sensitive sort

    Dear wysota,

    Thanks you sooo... much.

    tableWidget ()->horizontalHeader () ->sortIndicatorOrder ()
    - this helps me a lot to do proper sorting.

    Thank you.

  7. #7
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QTableWidget case sensitive sort

    this topic really help me,
    I think post the modified code may help more.
    Qt Code:
    1. //.h file
    2. class CTableWidgetItem: public QTableWidgetItem
    3. {
    4. public:
    5. CTableWidgetItem();
    6. CTableWidgetItem(const QString &text,int type= Type):QTableWidgetItem( text,type){};
    7. virtual bool operator<(const QTableWidgetItem &item) const;
    8. };
    9. //.cpp file
    10. CTableWidgetItem::CTableWidgetItem()
    11. {
    12. }
    13.  
    14. bool CTableWidgetItem::operator<(const QTableWidgetItem &item) const
    15. {
    16. if(text().toUpper()<item.text().toUpper())
    17. return true;
    18. else
    19. return false;
    20. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget case sensitive sort

    If we are using proxy model, the simple one can be sortCaseSensitivity : http://doc.qt.io/qt-4.8/qsortfilterp...nsitivity-prop
    Thanks :-)

  9. #9
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget case sensitive sort

    Quote Originally Posted by wysota View Post
    No, if the sort order is reversed, it has to be the greatest item of all, so it has to return false. I think it's best to reimplement QTableWidget::sortItems().
    Oops, of course Wysota You are right.

Similar Threads

  1. Custom sort with QTableWidget
    By nicolas44 in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2007, 00:47
  2. QTableWidget won't sort cellwidgets!!!
    By Arsenic in forum Qt Programming
    Replies: 7
    Last Post: 21st July 2007, 10:41

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.