PDA

View Full Version : connecting CheckBox inside QTableWidget with a function



Merkura
23rd May 2008, 10:23
Hi,

i have a QGraphicsItem that i want to be hidden or shown, due to its checkmark which i want to place inside a TableWidget. What i have so far:


QTableWidget *table = new QTableWidget(8,3);
QTableWidgetItem *item = new QTableWidgetItem(1);
item->data(Qt::CheckStateRole);
item->setCeckState(Qt::Checked);
table->setItem(3,0,item);

... which creates a wonderful CheckBox inside my table. But how can i link the check mark state to my GraphicsItem?
I tried several signals provided by the QTableWidget class, but some of the ones i tried produced a compiler error stating, that this signal doesn't exist. And the others that work, don't seem to be appropriate for my problem.

Thanks in advance!

jpn
25th May 2008, 13:14
But how can i link the check mark state to my GraphicsItem?
I tried several signals provided by the QTableWidget class, but some of the ones i tried produced a compiler error stating, that this signal doesn't exist. And the others that work, don't seem to be appropriate for my problem.
QTableWidget::itemChanged() is the closest you can get with available signals. You just have to keep in mind that it gets emitted whenever any item data changes, not just check state. A signal like checkStateChanged() has been requested but unfortunately Trolltech rejected the idea. See also QxtTableWidget (http://docs.libqxt.org/classQxtTableWidget.html).

vycke
5th June 2008, 21:32
You can set the pointer to your graphics item in the QTableWidgetItem (setData()), then use the QTableWidget signal itemClicked(QTableWidgetItem* item) & see if it's in the right column, or data() != NULL, or some other way to validate that it's one of your checkbox items. Then you can use the pointer to show/hide as needed.

Vycke