I've just started using Qt, so please bear with me. When I use QTableWidget->getItemAt(), it returns a different item from if I used currentItemChanged and clicked the same item. I believe it's necessary to use itemAt() since I need to get the first column of whatever row was clicked.
Some example code is below:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QList<QString> rowContents;
rowContents << "Foo" << "Bar" << "Baz" << "Qux" << "Quux" << "Corge" << "Grault" << "Garply" << "Waldo" << "Fred";
for(int i =0; i < 10; ++i)
{
ui->tableTest->insertRow(i);
ui->tableTest->setItem(i, 0, new QTableWidgetItem(rowContents[i]));
ui->tableTest->setItem(i, 1, new QTableWidgetItem(QString::number(i)));
}
}
//...
void MainWindow::on_tableTest_currentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous)
{
ui->lblColumn->setText(QString::number(current->column()));
ui->lblRow->setText(QString::number(current->row()));
ui->lblCurrentItem->setText(current->text());
ui->lblCurrentCell->setText(ui->tableTest->itemAt(current->row(), current->column())->text());
}
For the item at 1x9, lblCurrentItem displays "9" (as it should,) whereas lblCurrentCell displays "Quux". Am I doing something wrong?