Results 1 to 4 of 4

Thread: Adding row in a Table after selected row

  1. #1
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Adding row in a Table after selected row

    hi all,

    i want to add a row after the selected row in a table, made from QTableWidget.
    i used the function insertRow(int rowIndex), to insert the row in the table. Now this function adds the row before the rowIndex passed. i want to add the row after selected row. so i calculated the currentrow by currentRow and add 1 to the index and pass to the function insertRow. Problem occurs when i add after the last row in the table. The table crashes. in the middle of the table it works fine.

    can somebody suggest some way to do this ?
    Do what u r afraid to do, and the death of fear is sure.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Adding row in a Table after selected row

    Which version of Qt4 are you using?
    Unfortunately I couldn't connect to www.trolltech.com to check task tracker whether any bugs related to this exist.
    But anyway, it works fine (without any additional checks) for me with Qt 4.1.2:
    Qt Code:
    1. tableWidget->insertRow(tableWidget->currentRow()+1);
    To copy to clipboard, switch view to plain text mode 
    No matter if the last row or no row at all is selected...
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    ankurjain (20th April 2006)

  4. #3
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adding row in a Table after selected row

    hi,
    i m using the same version jpn. this means there is some problem in the project somewhere else. damn i hav to look out again in other's code. ok i try to sort this out and revert back if there is some problem.

    Quote Originally Posted by jpn
    No matter if the last row or no row at all is selected...
    but the row ( strictly speaking, item) has to be selected ,only then currentRow will return the index after which it will add. isn't it ??


    Thanx
    Last edited by ankurjain; 20th April 2006 at 13:26.
    Do what u r afraid to do, and the death of fear is sure.

  5. #4
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding row in a Table after selected row

    Technically, the 'currentRow' isn't necessarily the same as the 'selectedRow'. I always use the selected row because it will work even when your widget does not have keyboard focus. The currentRow will be undefined when your widget does not have focus.

    The selected row is a little harder to calculate (you have to look at the selected indexes of the selection model), but in most cases it is safer to use.
    Save yourself some pain. Learn C++ before learning Qt.

Similar Threads

  1. Postgresql QSqlRelationalTableModel empty table
    By RolandHughes in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2008, 17:18
  2. selected cells' table
    By dreamer in forum Qt Programming
    Replies: 5
    Last Post: 19th June 2008, 08:59
  3. Showing selected rows in a separate table
    By dnnc in forum Qt Programming
    Replies: 3
    Last Post: 21st June 2007, 16:35
  4. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  5. adding in values to table
    By therealjag in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2006, 16:05

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.