views:

260

answers:

3

i am using PyQt but my question is a general Qt one:

I have a QTableWidget that is set up by the function updateTable. It writes the data from DATASET to the table when it is called. Unfortunately this causes my QTableWidget to emit the signal cellChanged() for every cell.

The signal cellChanged() is connected to a function on_tableWidget_cellChanged that reads the contents of the changed cell and writes it back to DATASET. This is necessary to allow the user to change the data manually.

So everytime the table is updated, its contents are written back to DATASET.

Is there a way to distinguish if the cell was changed by the user or by updateTable?

i thought of disconnecting on_tableWidget_cellChanged by updateTable temporarily but that seems to be a little dirty.

+1  A: 

It seems, that this is the only signal in QTableWidget at least for 4.6. You could post a feature request, but I don't know if it is accepted and you might wait for long time ;-)

Maybe you could try to write a subclass of QTableWidget and emit own signals, when cell is changed internally.

Anyway, disconnecting for the time of updating the cell isn't that bad, since you can't connect to specific signal.

gruszczy
A: 

I would recommend changing from a QTableWidget to a QTableView with an appropriate model. From the sounds of it, you have a database or other data object holding and arranging the data anyway, so it would hopefully be fairly easy to do. This would then allow you to distinguish between edits (setData is called on your model) and updates (data is called on your model).

Caleb Huitt - cjhuitt
A: 

In similar situation I've just used

bool QObject::blockSignals ( bool block )
bool QObject::signalsBlocked () const

Block signals before setting up the table, then unblock:

myTable.blockSignals(True)
#blah-blah..
myTable.blockSignals(False)
Max