#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMainWindow>
#include <QTableWidget>
#include <QHeaderView>
#include <QGridLayout>
#include <QWidget>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QWidget *widget = new QWidget(this);
QGridLayout *layout = new QGridLayout();
layout->setSizeConstraint(QLayout::SetFixedSize);
for (int i = 0; i < 10; ++i) {
QTableWidget *table = new QTableWidget(this);
InitializeQtableWidget(table, 3, 5);
layout->addWidget(table);
}
widget->setLayout(layout);
setCentralWidget(widget);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::InitializeQtableWidget(QTableWidget *table, const int &rows, const int &columns)
{
table->setRowCount(rows);
table->setColumnCount(columns);
const int tableColumnWidth = 60;
const int tableRowHeight = 35;
for(int i = 0; i < columns; ++i)
table->setColumnWidth(i, tableColumnWidth);
table->verticalHeader()->setFixedWidth(tableColumnWidth);
table->horizontalHeader()->setFixedHeight(tableRowHeight + 5);
table->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
table->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
table->setFixedSize(table->horizontalHeader()->length() + table->verticalHeader()->width(),
table->verticalHeader()->length() + table->horizontalHeader()->height());
}