zarkzervo
7th January 2009, 08:53
I have a QTableWidget containing 10 columns.
I have an object myCar *Car which keeps a pointer to the QTableWidgetItems in a row:
QTableWidgetItem *item_id;
QTableWidgetItem *item_depth;
QTableWidgetItem *item_angle; and so on...
I then select a cell containing the item_depth (this works).
I can sort on any column and it still works.
I then start updating the data in several cells like this:
item_depth->setText(QString::number(car->depth()));
(all but the ID are frequently updated)
The selection still works and follows the Car object up and down the table.
I can select 5 cells on the same row (belonging to the Car object) and the selection keeps to the same row.
Then I select the sixth cell on the same row. The next update, suddenly one of the selections 'jumps' to another row. The data on each row are correct, but the selection is not keeping to the correct row. Some of them are sticking to the original row, but one of the selections have jumped to a different row and stays there.
Some times this anomality begins at the 3rd selected and other times 4th, so there is no "6th time consistency".
Also if I sort on item_id, this does not occur because then the rows are not moved.
I discovered the error as I had enabled selection of whole rows of data:
tbl_cars->setSelectionBehavior(QAbstractItemView::SelectRows );
Any suggestions on what i should do?
I have added all QTableWidgetItems to the table and only used setText() on them to change the text, i.e., I have not added more cells/rows as I know sorting should be turned off before addition.
I do turn of sorting before adding a row and turn it on afterwards.
I have an object myCar *Car which keeps a pointer to the QTableWidgetItems in a row:
QTableWidgetItem *item_id;
QTableWidgetItem *item_depth;
QTableWidgetItem *item_angle; and so on...
I then select a cell containing the item_depth (this works).
I can sort on any column and it still works.
I then start updating the data in several cells like this:
item_depth->setText(QString::number(car->depth()));
(all but the ID are frequently updated)
The selection still works and follows the Car object up and down the table.
I can select 5 cells on the same row (belonging to the Car object) and the selection keeps to the same row.
Then I select the sixth cell on the same row. The next update, suddenly one of the selections 'jumps' to another row. The data on each row are correct, but the selection is not keeping to the correct row. Some of them are sticking to the original row, but one of the selections have jumped to a different row and stays there.
Some times this anomality begins at the 3rd selected and other times 4th, so there is no "6th time consistency".
Also if I sort on item_id, this does not occur because then the rows are not moved.
I discovered the error as I had enabled selection of whole rows of data:
tbl_cars->setSelectionBehavior(QAbstractItemView::SelectRows );
Any suggestions on what i should do?
I have added all QTableWidgetItems to the table and only used setText() on them to change the text, i.e., I have not added more cells/rows as I know sorting should be turned off before addition.
I do turn of sorting before adding a row and turn it on afterwards.