QTableView empty space or too little space.
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:
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;
}
which is called from (editted version):
Code:
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);
Any clues will be welcome.
Re: QTableView empty space or too little space.
what about setHorizontalScrollBarPolicy () (and vertical)?
Re: QTableView empty space or too little space.
No, that doesn't seem to work. I can remove the scroll bar using it, but it doesn't enlarge the box to allow the table to fit in. It just shows the first couple of rows without a scroll bar.