Results 1 to 2 of 2

Thread: QTableView insertRow 's dynamically

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: QTableView insertRow 's dynamically

    When inserting rows into QTableWidget, you need to disable sorting.

    1. Disable Sorting
    2. Insert Row(s), set all items in the row.
    3. Enable Sorting

    This is because, with sorting enabled, as soon as you insert a new item in a row, QTableWidget runs the sorting check on the new row item and relocates the item as per set sorting order, this means that the item row number is changed, and the row variable which you hold is no more valid, and when you to set the next item on the same row, it will give you spurious results, as the row variable is not valid any more

    Other alternate to disable sorting, is to get the latest row number before setting the item, like this

    1. Insert a new row (say row)
    2. Set new item at row, at column 0
    3. Get the new row number of the newly set item at column 0
    4. Set next item at new row, at column 1
    ....next columns, as needed

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

    migel (30th June 2011)

Similar Threads

  1. how to add tab dynamically
    By asish_cse in forum Newbie
    Replies: 2
    Last Post: 14th September 2010, 16:27
  2. How to InsertRow Throught QSqlQueryModel ?
    By innobleday in forum Qt Programming
    Replies: 0
    Last Post: 24th March 2010, 04:44
  3. Replies: 2
    Last Post: 11th January 2010, 11:39
  4. QStandardItemModel insertRow crashing
    By munna in forum Qt Programming
    Replies: 1
    Last Post: 27th June 2008, 11:55
  5. QTableView QTablemodel & insertRow
    By pfusterschmied in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2007, 12:43

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
  •  
Qt is a trademark of The Qt Company.