[Interest] Telling which QTableWidgetItem was changed?

Robert Wood robert.wood at apostrophe.co.uk
Tue Jul 1 14:08:42 CEST 2014


FWIW, and maybe this will help someone else because I've seen a zillion 
similar requests with Google searches and no decipherable answer:

     row = ui->innoLEDListTable->rowCount();
     ui->innoLEDListTable->insertRow(row);
     QTableWidgetItem *tw = new QTableWidgetItem(row);
     tw->data(Qt::CheckStateRole);
     tw->setCheckState(Qt::Checked);
     tw->setText(QString::number(row,10));
     ui->innoLEDListTable->setItem(row,0,tw);

Connect like this:

connect(ui->innoLEDListTable,SIGNAL(itemChanged(QTableWidgetItem*)),this,SLOT(tableItemClicked(QTableWidgetItem*)));

But only have that line called ONCE otherwise you get the slot called 
the number of times that you have number of rows :~D

void MainWindow::tableItemClicked(QTableWidgetItem * item)
{

         ui->textEdit->append("Somethig clicked " + item->text() );


}

Works a treat and you call tell which one has been pressed by the item's 
text (as long as you give it a unique text.


On 01/07/14 11:26, Robert Wood wrote:
> Folks,
>
> I have a dynamically created table; whenever I add a new row, I do this:
>
>       QCheckBox *cb = new QCheckBox();
>       ui->innoLEDListTable->setCellWidget(row,0,cb);
>
>
>       connect(cb,SIGNAL(clicked()),this,SLOT(tableItemClicked()));
>
>
> Now this works fine in that whenever I click a check box in the table,
> it calls my function tableItemClicked(). However, having tried a
> plethora of different ways, I cannot work out how to have the called
> function detect which check box it was that was ticked or cleared. There
> must be a way of doing it!
>
> I thought this was going to solve it:
>
> http://www.qtforum.org/article/26960/qtablewidgetitem-signals.html
>
> But I get this error:
>
> /usr/lib64/qt5/include/QtCore/qobjectdefs.h:489: error: 'qt_metacall' is
> not a member of 'QTableWidgetItem'
>            enum { Value =  sizeof(test(&Object::qt_metacall)) ==
> sizeof(int) };
>                                        ^
> To make things clear, each new row I insert in the table, when the check
> box is clicked, I successfully call my function, it's just I need to
> work out which of the [potentially] many check boxes was clicked to take
> me to that slot!
>
> Many thanks,
>
> Rob
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>



More information about the Interest mailing list