QTableWidget signal cellChanged (): distinguish user input and change by procedure

I am using PyQt, but my question is general Qt:

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

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

Therefore, every time a table is updated, its contents are written to DATASET.

Is it possible to distinguish whether the cell has been changed by the user or updated?

I was thinking of disabling on_tableWidget_cellChanged by updateTable temporarily, but it seems a bit dirty.

+3
source share
3 answers

In a similar situation, I just used

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

Block signals before setting up the table, then unlock:

myTable.blockSignals(True)
#blah-blah..
myTable.blockSignals(False)
+5
source

This seems to be the only signal in QTableWidget, at least for 4.6. You can send a function request, but I do not know if it is accepted, and you can wait a long time; -)

Perhaps you could try to write a subclass of QTableWidget and emit your own signals when the cell is changed inside.

, , .

+1

QTableWidget QTableView . , , , . (setData ) (data ).

+1

Source: https://habr.com/ru/post/1736627/


All Articles