Problem with QTableWidget and Signals
Hi all,
I have a QtableWidget defines as follows:
Code:
for (int row_j=0; row_j < 3; ++row_j)
{
for (int column_i=0; column_i < 4; column_i++)
{
item->setTextAlignment (Qt::AlignCenter);
tableWidget->setItem(row_j, column_i, item);
}
}
tableWidget->item(0, 0)->setCheckState ( Qt::Checked ); <------
tableWidget->item(1, 0)->setCheckState ( Qt::Checked ); <------
tableWidget->item(2, 0)->setCheckState ( Qt::Checked ); <------
TableLayout->addWidget (tableWidget);
layout->addWidget(frameQTable);
setLayout(layout);
Using the code as the shows by the arrows above, I put into the first cell of each row a CheckBox..
The Question is :
is there a way to emit a signal when the I click on the CheckBox?
So far the only signal is working for me is itemSelectionChanged ():
Code:
connect(tableWidget, SIGNAL(itemSelectionChanged () ),
this, SIGNAL(completeChanged()));
that works indeed when I move to another item....
but not when I put the check..
Thank you for your kind reply..
Roberto
Re: Problem with QTableWidget and Signals
Try connecting to QTableWidget::cellChanged() and check the Qt::CheckStateRole of the item.
HTH
Re: Problem with QTableWidget and Signals
Nothing happens whe I click on the checkbox...
Ho do I have to use the Qt::CheckStateRole
Here is the code I use:
Code:
what I am trying:
connect(tableWidget, SIGNAL(cellChanged(0,0) ),
this, SIGNAL(completeChanged()));
and then in the method called I have the code:
if ( (tableWidget->item(1, 0)->checkState () != Qt::Checked) )
{
return false;
}
else
return true;
but nothing..
Thx
Re: Problem with QTableWidget and Signals
You must not use values for the arguments of the slot in the connect call!
(You should get an error message printed for your code, by the way.)
Try like this
Code:
connect(tableWidget, SIGNAL(cellChanged(int,int) ),
this, SIGNAL(completeChanged(int,int)));
Code:
void completeChanged(int row, int col)
{
if (item->checkState() == ...)
...
}
Re: Problem with QTableWidget and Signals
BINGOOO!!!
It works Perfectly...as you suggested..
GREAT!
Many thanks..
Roberto