I've got a QTableView containing a QStandardItemModel which gives a table of 2 columns, 4 rows, with both horizontal and vertical headers on each (so a 3x5 grid). I've put this QTableView inside a QGroupBox which is part of the main QGridLayout.
I'd like the table to appear with all the cells with no scrollbars and no blank space, but I can't achieve it. I'm managed to remove the blank space down the right-hand side using table->horizontalHeader()->setResizeMode(QHeaderView::Stretch), but can't find an equivalent to remove the vertical scroll bar and/or the empty space at the bottom.
Here's a snippet of the code:
{
line_model->setHeaderData(0, Qt::Horizontal, tr("Start"));
line_model->setHeaderData(1, Qt::Horizontal, tr("End"));
line_model->setHeaderData(0, Qt::Vertical, tr("Index"));
line_model->setHeaderData(1, Qt::Vertical, tr("X"));
line_model->setHeaderData(2, Qt::Vertical, tr("Y"));
line_model->setHeaderData(3, Qt::Vertical, tr("Z"));
// line_model has values placed in it elsewhere.
table->setModel(line_model);
table->setSelectionModel(selectionModel);
table
->horizontalHeader
()->setResizeMode
(QHeaderView::Stretch);
layout->addWidget(table);
line_box->setLayout(layout);
return line_box;
}
QGroupBox *Window::SetLineTableLayout()
{
line_model = new QStandardItemModel(4, 2, this);
line_model->setHeaderData(0, Qt::Horizontal, tr("Start"));
line_model->setHeaderData(1, Qt::Horizontal, tr("End"));
line_model->setHeaderData(0, Qt::Vertical, tr("Index"));
line_model->setHeaderData(1, Qt::Vertical, tr("X"));
line_model->setHeaderData(2, Qt::Vertical, tr("Y"));
line_model->setHeaderData(3, Qt::Vertical, tr("Z"));
// line_model has values placed in it elsewhere.
QTableView *table = new QTableView;
table->setModel(line_model);
QItemSelectionModel *selectionModel = new QItemSelectionModel(line_model);
table->setSelectionModel(selectionModel);
table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
QGroupBox *line_box = new QGroupBox(tr("Selected Line"));
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(table);
line_box->setLayout(layout);
return line_box;
}
To copy to clipboard, switch view to plain text mode
which is called from (editted version):
line_box = SetLineTableLayout();
mainLayout->addWidget(line_box, 1, 1, 1, 1);
// Lots of other widgets added to the grid not shown here for clarity.
setLayout(mainLayout);
QGridLayout *mainLayout = new QGridLayout;
QGroupBox *line_box = new QGroupBox;
line_box = SetLineTableLayout();
mainLayout->addWidget(line_box, 1, 1, 1, 1);
// Lots of other widgets added to the grid not shown here for clarity.
setLayout(mainLayout);
To copy to clipboard, switch view to plain text mode
Any clues will be welcome.
Bookmarks