Results 1 to 2 of 2

Thread: A problem with sorting QTableWidget by column

  1. #1
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: A problem with sorting QTableWidget by column

    Hello!

    My QTableWidget object is being filled from a database. Everything went okay until I had to sort the second column by ascending. So I wrote:
    Qt Code:
    1. ui.tableWidget->sortByColumn(2, Qt::AscendingOrder);
    To copy to clipboard, switch view to plain text mode 
    When I ran the application I found that a lot of cells of the table widget are empty. Why is that so? Would anybody help me please?


    Added after 15 minutes:


    Oh, I think I have just solved the problem. I have added ui.tableWidget->setSortingEnabled(false); before filling the widget ui.tableWidget->setItem(rowNumber, i ,item); and after that - ui.tableWidget->setSortingEnabled(true);
    Now everything works fine.
    Sorry for that thread. I asked a question and answered it on my own.
    Last edited by tehman; 6th February 2012 at 08:37.

  2. The following user says thank you to tehman for this useful post:

    jgver (15th February 2012)

  3. #2
    Join Date
    Aug 2008
    Location
    Eastern U.S.
    Posts
    9
    Thanks
    1
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: A problem with sorting QTableWidget by column

    Thanks for this post. I just ran into the same problem, and this post saved me!

Similar Threads

  1. QTableWidget column based sorting
    By shadowfax in forum Newbie
    Replies: 3
    Last Post: 21st August 2012, 12:22
  2. Replies: 0
    Last Post: 18th October 2010, 12:59
  3. Dynamic sorting using proper column after adding a row.
    By kremuwa in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2010, 00:50
  4. Sorting column in QTreeWidget
    By lni in forum Qt Programming
    Replies: 8
    Last Post: 14th November 2007, 19:35
  5. Column Sorting
    By sumsin in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2006, 08:48

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.