TableView store contents of particular cell in variable
Ok I have a table populated with data from my database.
What i want is when a user selects a cell and a button is pressed, the data within the cell they selected is used in a function as a variable. I have no idea how to achieve this. Could someone please point me in the right direction.
Thanks for your time and trouble :D
Re: TableView store contents of particular cell in variable
In the slot reacting to the button, use the view's QItemSelectionModel to determine the current cell's QModelIndex. Then retrieve the value of the Qt::DisplayRole (or whatever) for that index from the model (not the view).
Re: TableView store contents of particular cell in variable
Could you perhaps give me some example code? I'm new at this and really confused.
Code:
UserWindow
::UserWindow(QWidget *parent
) : ui(new Ui::UserWindow)
{
//Other code here
query.exec(querystring);
model->setQuery(query);
model->removeColumn(0);
model->removeColumn(1);
model->setHeaderData(0, Qt::Horizontal, "Name");
model->setHeaderData(1, Qt::Horizontal, "Date");
model->setHeaderData(2, Qt::Horizontal, "Completed");
// Populate the table with the relevant information from the database
ui->tableView->setModel(model);
ui->tableView->show();
}
void UserWindow::on_NextButton_clicked()
{
// What do I do here?
// I want the value within the currently selected cell to be used here.
// Could someone give me some example code to demonstrate how to do this.
}
Thanks