'How can I block QTableWidget signals after disabling the table?
I have a python QTableWidget populated with 4 columns. Selecting any of the columns runs the qTableWidget.cellClicked() signal, which then highlights the entire row, and runs a bunch of code.
self._qTableWidget.cellClicked.connect(self.cellClicked)
def cellClicked(self, row, column):
"""
Handle cell clicked signal.
"""
self._qTableWidget.setDisabled(True)
qTableWidgetItem = self._qTableWidget.item(row, column)
if qTableWidgetItem is None:
return
else:
# ***RUNS SOME CODE***
pass
self._qTableWidget.setEnabled(True)
In the code, I want to disable the QTableWidget from accepting any clicks until after the code runs, then enable the QTableWidget (which I have tried by using setDisabled()/setEnabled()).
However if you click a cell, the table is disabled correctly, but you can still click on cells in the table. When the table is enabled again, it runs the cellClicked() signal again on the QTableWidgetItem you clicked on while the table was disabled.
I have tried using the following:
self._qTableWidget.blockSignals(True)
self._qTableWidget.blockSignals(False)
self._qTableWidget.cellClicked.disconnect(self.cellClicked)
self._qTableWidget.cellClicked.connect(self.cellClicked)
self.setAllCellItemFlags(QtCore.Qt.NoItemFlags)
def setAllCellItemFlags(self, flag):
"""
Sets all QTableWidgetItem flags
"""
for row in range(self._qTableWidget.rowCount()):
for column in range(self._qTableWidget.columnCount()):
qTableWidgetItem = self._qTableWidget.item(row, column)
qTableWidgetItem.setFlags(flag)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
