C++ (Qt) modelBooks = new QSqlRelationalTableModel(this, db); modelBooks->setTable("books"); modelBooks->setEditStrategy(QSqlTableModel::OnManualSubmit); seriesIndex = modelBooks->fieldIndex("series_id"); modelBooks->setRelation(seriesIndex, QSqlRelation("series", "id", "series")); langsIndex = modelBooks->fieldIndex("langs_id"); modelBooks->setRelation(langsIndex, QSqlRelation("langs", "id", "language")); publishersIndex = modelBooks->fieldIndex("publisher_id"); modelBooks->setRelation(publishersIndex, QSqlRelation("publishers", "id", "publisher")); if (!modelBooks->select()) { showError(modelBooks->lastError()); return; } modelBooks->setHeaderData(1, Qt::Horizontal, QObject::trUtf8("Название")); modelBooks->setHeaderData(3, Qt::Horizontal, QObject::trUtf8("Год")); ui->tableViewBooks->setModel(modelBooks); ui->tableViewBooks->resizeColumnsToContents(); ui->tableViewBooks->setCurrentIndex(modelBooks->index(0, 0)); ui->tableViewBooks->setColumnHidden(0, true); ui->tableViewBooks->setColumnHidden(5, true); ui->tableViewBooks->setSelectionBehavior(QAbstractItemView::SelectRows); ui->tableViewBooks->setSelectionMode(QAbstractItemView::SingleSelection); ui->tableViewBooks->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
напротив каждой книги ставить формат
C++ (Qt) formatIndex = modelBooks->fieldIndex("format_id"); modelBooks->setRelation(formatIndex, QSqlRelation("formats", "id", "mimetype"));