PDA

View Full Version : Adding row in a Table after selected row



ankurjain
20th April 2006, 12:33
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 ?

jpn
20th April 2006, 13:15
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:


tableWidget->insertRow(tableWidget->currentRow()+1);

No matter if the last row or no row at all is selected...

ankurjain
20th April 2006, 13:22
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.



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

Chicken Blood Machine
20th April 2006, 18:06
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.