QTableWidget still trigger itemChanged event even if signals blocked
-
Hi guys,
As title, i'm facing with the problem that i have blocked all signals of QTableWidget but the setItem function still trigger itemChanged event.Is there anyway to prevent itemChanged trigger?
I just know one solution is wrap before and after setItem function by blockSignals(true) again.
But its very annoying if my table have too much cell to set. -
Please show how you're using block signals and your connect statement.
-
Please show how you're using block signals and your connect statement.
@Christian-Ehrlicher said in QTableWidget still trigger itemChanged event even if signals blocked:
Please show how you're using block signals and your connect statement.
Hi christ,
i just block signals like normaltable->blockSignals(true); // ... Some other logics table->setItem(0, 0, value0); table->setItem(0, 1, value1); table->setItem(0, 2, value2); table->setItem(0, 3, value3); // ... Some other logics table->blockSignals(false);And i using qt designer to create connect (by right click widget and then choose "go to slot..."
-
Works fine for me (Qt6):
#include <QtWidgets> int main(int argc, char **argv) { QApplication app(argc, argv); bool blockSignals = argc > 1; QTableWidget tw; tw.show(); tw.setColumnCount(1); tw.setRowCount(1); QObject::connect(&tw, &QTableWidget::itemChanged, [&]() { qDebug() << "Item changed!"; }); QTimer::singleShot(10, &tw, [&]() { if (blockSignals) tw.blockSignals(true); tw.setItem(0, 0, new QTableWidgetItem("Blub")); if (blockSignals) tw.blockSignals(false); }); return app.exec(); } -
@Christian-Ehrlicher said in QTableWidget still trigger itemChanged event even if signals blocked:
Please show how you're using block signals and your connect statement.
Hi christ,
i just block signals like normaltable->blockSignals(true); // ... Some other logics table->setItem(0, 0, value0); table->setItem(0, 1, value1); table->setItem(0, 2, value2); table->setItem(0, 3, value3); // ... Some other logics table->blockSignals(false);And i using qt designer to create connect (by right click widget and then choose "go to slot..."
@Sabrac
there is a return value from blockSignals(true). Check it out. The return value is the previous value of signalsBlocked().
https://doc.qt.io/qt-5.15/qobject.html#blockSignalsThere is another way to avoid any unnecessary changes caused by a specific signal.
disconnect( table, signal, this, slot); // ... Some other logics table->setItem(0, 0, value0); table->setItem(0, 1, value1); table->setItem(0, 2, value2); table->setItem(0, 3, value3); // ... Some other logics connect( table, signal, this, slot);This may work better sometimes since you may not want to block all signals.