CheckForm::CheckForm(QWidget *parent) :QDialog(parent){ setWindowFlags(Qt::Window); checkModel = new QSqlRelationalTableModel; checkModel->setTable("send"); checkModel->setRelation(Check_Product, QSqlRelation("product", "id", "title")); checkModel->setSort(Check_Id, Qt::AscendingOrder); checkModel->setHeaderData(Check_Mark, Qt::Horizontal, tr("обозначение")); checkModel->setHeaderData(Check_Det, Qt::Horizontal, tr("наименование")); checkModel->setHeaderData(Check_SendSum, Qt::Horizontal, tr("сдано")); checkModel->setHeaderData(Check_SendDate, Qt::Horizontal, tr("дата и время сдачи")); checkModel->setHeaderData(Check_RecvSum, Qt::Horizontal, tr("принято")); checkModel->setHeaderData(Check_RecvDate, Qt::Horizontal, tr("дата и время приема")); checkModel->setHeaderData(Check_Product, Qt::Horizontal, tr("Изделие")); checkModel->setEditStrategy(QSqlTableModel::OnFieldChange); checkModel->select(); checkTableView = new QTableView; checkTableView->setModel(checkModel); checkTableView->setColumnHidden(Check_Id, true); checkTableView->setSelectionBehavior(QAbstractItemView::SelectRows); checkTableView->resizeColumnsToContents(); deleteButton = new QPushButton(tr("Удалить")); closeButton = new QPushButton(tr("Закрыть")); connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteCheck())); tabBar = new QTabBar(this); tabBar->addTab(tr("из 3 в 4")); tabBar->addTab(tr("из 3 на склад")); connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(changeTable(int))); QGridLayout *lay = new QGridLayout; lay->addWidget(tabWidget, 0, 0); lay->addWidget(checkTableView, 1, 0, 4, 1); lay->addWidget(deleteButton, 1, 1, 1, 1); lay->addWidget(closeButton, 3,1,1,1); lay->setRowStretch(2,10); setLayout(lay); resize (1024, 640); setWindowTitle(tr("Акты сдачи/приёмки"));}void CheckForm::changeTable(int tab){ if(tab==0){ checkModel->setTable("send"); checkModel->select(); } if(tab==1){ checkModel->setTable("store"); checkModel->select(); }}
QGridLayout *lay = new QGridLayout; lay->addWidget(tabBar, 0, 0); lay->addWidget(checkTableView, 1, 0, 4, 1); lay->addWidget(deleteButton, 1, 1, 1, 1); lay->addWidget(closeButton, 3,1,1,1); lay->setRowStretch(2,10); setLayout(lay);
C++ (Qt)lay->setSpacing( 0 );
C++ (Qt)tabBar->setDrawBase(false);