PDA

View Full Version : QTableWidget signals



QiT
1st April 2007, 12:54
Hi all;


I am using a QTableWidget with combobox item and spinboxItem. What signal should I use to know if one item has his value changed.


thanks

fullmetalcoder
1st April 2007, 13:08
http://doc.trolltech.com/4.2/qtablewidget.html#itemChanged

just wondering... Is browsing the doc sooooooooo tedious??? ;)

jpn
1st April 2007, 13:33
Just as a side node, the table widget does not emit any signals in case those are cell widgets. The cell widgets itself emit their own signals when their values change.

Btw, is it an ordinary spinbox with plain numerical data? Another (and much more light-weight) option would be to set the data to the table widget items as numbers, not as text. Then the delegate would provide a spinbox as an editor, out of the box.



int number = 123;
QTableWidgetItem* item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, number);
// i don't remember if table widget items are editable by default,
// the following line will make sure they are
item->setFlags(item->flags() | Qt::ItemIsEditable);
tableWidget->setItem(row, col, item);

QiT
1st April 2007, 13:50
thanks for help but it is not working.

I want make the saveBotton not disabled when I make a change in the QTableWidget.



void MyClass::on_tableWidget_itemChanged(QTableWidgetIt em*)
{
ui.SaveBotton->setDisabled(false);
}

fullmetalcoder
1st April 2007, 14:03
Do you have access to the widgets when they are created? If so just connect proper signals...

Otherwise you should :
add a QPointer<QWidget*>member
on QTableWidget::cellActivated() (http://doc.trolltech.com/latest/qtablewidget.html#cellActivated), if non-zero, disconnect its proper signal (change of value) from your enable/disable slot
set it to QTableWidget::cellWidget() (http://doc.trolltech.com/latest/qtablewidget.html#cellWidget) and connect its proper signal to your enable/disable slot

// assuming the class as a member like : QPointer<QWidget*> m_cellwidget

void MyClass::on_tableWidget_cellActivated(int row, int column)
{
if ( m_cellwidget )
{
disconnect(m_cellwidget, SIGNAL( ),
this , SLOT ( ) );

}

m_cellwidget = cellWidget(row, column);

if ( m_cellwidget )
{
connect(m_cellwidget, SIGNAL( ),
this , SLOT ( ) );

}
}



P.S. : Don't forget to fill in the blanks...;) Also as you mentionned that your widgets are of two types you should check for this and choose the appropriate signal...

Hope this helps.:)