bytefish
28th March 2011, 13:32
Hi,
I want to display a QPushButton next to a row in a QSqlTableModel. The approach I have taken is using the setIndexWidget method and mapping the Button to the row with a QSignalMapper:
int column = model->columnCount();
model->insertColumn(column);
QSignalMapper *sigMap = new QSignalMapper(this);
QPushButton *button;
for(int i = 0; i < model->rowCount(); i++) {
button = new QPushButton(ui->tblViewClient);
button->setText("Show Details");
connect(button, SIGNAL(clicked()), sigMap, SLOT(map()));
sigMap->setMapping(button, model->data(model->index(i,0)).toInt());
ui->tblViewClient->setIndexWidget(model->index(i,column), button);
}
connect(sigMap, SIGNAL(mapped(int)), this, SLOT(showDetails(int)));
This works fine for me. But... On double clicking a row I am displaying the models data with a QDataWidgetMapper. If I close this dialog the model emits a dataChanged signal, the tableView gets rerendered and my buttons get lost (because I am using a QSqlTableModel...).
My question is, can you think of a simple way to avoid this? Connecting to dataChanged and repainting the whole thing does not help.
I hope my first post here is not too weird. :-)
Kind regards,
Philipp.
I want to display a QPushButton next to a row in a QSqlTableModel. The approach I have taken is using the setIndexWidget method and mapping the Button to the row with a QSignalMapper:
int column = model->columnCount();
model->insertColumn(column);
QSignalMapper *sigMap = new QSignalMapper(this);
QPushButton *button;
for(int i = 0; i < model->rowCount(); i++) {
button = new QPushButton(ui->tblViewClient);
button->setText("Show Details");
connect(button, SIGNAL(clicked()), sigMap, SLOT(map()));
sigMap->setMapping(button, model->data(model->index(i,0)).toInt());
ui->tblViewClient->setIndexWidget(model->index(i,column), button);
}
connect(sigMap, SIGNAL(mapped(int)), this, SLOT(showDetails(int)));
This works fine for me. But... On double clicking a row I am displaying the models data with a QDataWidgetMapper. If I close this dialog the model emits a dataChanged signal, the tableView gets rerendered and my buttons get lost (because I am using a QSqlTableModel...).
My question is, can you think of a simple way to avoid this? Connecting to dataChanged and repainting the whole thing does not help.
I hope my first post here is not too weird. :-)
Kind regards,
Philipp.