How to get row and column in QTablewidget?
-
hi
i create 3 row and column Qtablewidget. last column have QPushButton. How to write clicked() event?
How to get particular row and column in Qtablewidget?i try...
@QPushButton *btn_attempt = new QPushButton("CDiff");@
@connect(btn_attempt, SIGNAL( cellClicked(int,int) ), this, SLOT( RemarksCall(int, int) ) );@@void tableDialog::RemarksCall(int row, int col)
{
QMessageBox msgBox;
QTableWidgetItem* theItem = ui.tableWidget->item( row, col);
QString theText = theItem->text();
msgBox.about(this,"Testy",theText);
}@but not get row and column value
-
Hi,
You can have a look in "here":http://qt-project.org/forums/viewthread/16673/ , There a QTableView is used instead of QTableWidget(your requirement).
Your code work's for other cells in the tableWidget if i write,
@ connect(ui->tableWidget,SIGNAL(cellClicked(int,int)),this,SLOT(remarksCall(int,int)));@
Also try to Right Click on your pushButton. It will show a messageBox with row and columns. You need to handle for Left Click.
You can have a look at "QSignalMapper":http://qt-project.org/doc/qt-4.8/qsignalmapper.html#details.
Also in line 4 it should be
@QTableWidgetItem* theItem = ui->tableWidget->item( row, col); @
instead of ui.tableWidget :)
-
QPushButton does not have a signal cellClicked(int,int). It has, for example, a clicked() signal, that you can connect to your slot. clicked() doesn't have any arguments, you'll have to do some bookkeeping yourself, for example using a [[Doc:QSignalMapper]].
-
hi, try this
@
connect(ui->tableWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(getText()));
// or
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(getText()));
@
and
@
void tableDialog::getText(){
QString text;
text = ui->tableWidget->item(ui->tableWidget->currentRow(), ui->tableWidget->currentColumn())->text();
}
@