The code you posted seems ok (next time please use the CODE tags). Is the second column shown if you disable sorting? How do you populate the table?
The code you posted seems ok (next time please use the CODE tags). Is the second column shown if you disable sorting? How do you populate the table?
is it necessary dat evry tim we add a row sortin needs to b disabled
bcoz i add a row n populate it at run tim after takin data from user????????
yes strangely it gets displayed correctly if sortin is disabled....
row=table->rowCount();
table->insertRow(table->rowCount());
QTableWidgetItem *fir = new QTableWidgetItem();
QTableWidgetItem *sec = new QTableWidgetItem();
fir->setText(QString::number(a));
sec->setText(QString::number(b,16));
table->setItem(row, 0, fir);
table->setItem(row, 1, sec);
row++;
table->setSortingEnabled(true);
Correction:
After inserting the first item "row" is not correct anymore for your second item.void QTableWidget::setItem ( int row, int column, QTableWidgetItem * item )
Sets the item for the given row and column to item.
The table takes ownership of the item.
Note that if sorting is enabled (see sortingEnabled) and column is the current sort column, the row will be moved to the sorted position determined by item.
If you want to set several items of a particular row (say, by calling setItem() in a loop), you may want to turn off sorting before doing so, and turn it back on afterwards; this will allow you to use the same row argument for all items in the same row (i.e. setItem() will not move the row).
See also item() and takeItem().
ok ....i got it....
n i rectified the row problem too...
its workin if i disable sorting before adding a row...
thnks a lot
sortin is working correctly only for 3 rows....
when 4-5 or more rows are being added its not sorting correctly...
why is it happening so...??
What are your values in the sorting column? Be aware using the constructor of QTabelWidgetItem will all input handle as strings. (and orderm them like strings.) If you have integers better use setData with the display role.
Bookmarks