View Full Version : Intercepting Events Emitted by QTableWidgetItem Objects

21st August 2007, 17:02

I'm trying to link up and keep in sync two QTableWidget objects which contain check boxes. Both tables may have 40, 80 or 160 items. When an item in one of the tables is checked, it also checks a number of some other related items in the same table using setCheckState(Qt::Checked). This may cause further check operations to propagate until a stable state is reached. At the same time, whenever an item in the first table is checked, the corresponding item is checked in the second table creating an avalanche of change events. On top of that, the second table also bounces back events and tries to check items in the first table. I found that this is not only slow but also crashes the application probably because of the call stack overflow. I tried to implement en event filter on the QTableWidget table but it didn't work. I also tried to implement the same filter on the QTableWidget's model object but it also failed to trap check events. QTableWidgetItem class doesn't inherit from QObject or any other class so it cannot have event filters. Finally, I tried to inherit from QTableWidgetItem and re-implement setData() controlling calls to model->itemChanged(this); but new setData() will have to access private data from QTableWidgetItem. I know it sounds like a bad design, but I have no time to reimplement the code that someone has already put in place. Basically, all I want is to be able to set checkbox items in a table without triggering itemChanged events. Can someone help ,please?

Kind Regards,
E Gruber

21st August 2007, 17:25
I warmly suggest you to consider rewriting it with clean model-view approach. However, since there is no time, you could try working it around for now by temporarily blocking signals with QObject::blockSignals().