Hi,
I solved this kind of "situation" in a very "craft" way:
...
: QDialog(parent
), ui
(new Ui
::Dialog) {
ui->setupUi(this);
ui->fileNameLabel->setText("pessoa.png");
setModel();
setView();
...
}
void Dialog::setModel()
{
model->setTable("photo");
model->setHeaderData(photo_id, Qt::Horizontal, tr("ID"));
model->setHeaderData(photo_name, Qt::Horizontal, trUtf8("Filename"));
model->setHeaderData(photo_image, Qt::Horizontal, trUtf8("Image"));
model->select();
}
void Dialog::setView()
{
view = ui->tableView;
view->setModel(model);
view->setColumnHidden(photo_image, true);
view->horizontalHeader()->setStretchLastSection(true);
}
...
Dialog::Dialog(QWidget *parent)
: QDialog(parent), ui(new Ui::Dialog)
{
ui->setupUi(this);
ui->fileNameLabel->setText("pessoa.png");
model = new QSqlTableModel(this);
setModel();
setView();
...
}
void Dialog::setModel()
{
model->setTable("photo");
model->setHeaderData(photo_id, Qt::Horizontal, tr("ID"));
model->setHeaderData(photo_name, Qt::Horizontal, trUtf8("Filename"));
model->setHeaderData(photo_image, Qt::Horizontal, trUtf8("Image"));
model->select();
}
void Dialog::setView()
{
view = ui->tableView;
view->setModel(model);
view->setColumnHidden(photo_image, true);
view->horizontalHeader()->setStretchLastSection(true);
view->setSelectionMode(QAbstractItemView::SingleSelection);
view->setSelectionBehavior(QAbstractItemView::SelectRows);
}
To copy to clipboard, switch view to plain text mode
This way i call setView() when i need to make sure that model and view are sinchronized.
Bookmarks