Results 1 to 2 of 2

Thread: A problem with sorting QTableWidget by column

  1. #1
    Join Date
    Jan 2012
    Thanked 1 Time in 1 Post

    Default Re: A problem with sorting QTableWidget by column


    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 07:37.

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

    jgver (15th February 2012)

  3. #2
    Join Date
    Aug 2008
    Eastern U.S.
    Qt products
    Qt4 PyQt3 PyQt4
    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, 11:22
  2. Replies: 0
    Last Post: 18th October 2010, 11:59
  3. Dynamic sorting using proper column after adding a row.
    By kremuwa in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2010, 23:50
  4. Sorting column in QTreeWidget
    By lni in forum Qt Programming
    Replies: 8
    Last Post: 14th November 2007, 18:35
  5. Column Sorting
    By sumsin in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2006, 07:48

Tags for this Thread


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.