PDA

View Full Version : QTableView empty space or too little space.



davemar
15th October 2009, 14:35
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:


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;
}


which is called from (editted version):


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);


Any clues will be welcome.

high_flyer
15th October 2009, 17:28
what about setHorizontalScrollBarPolicy () (and vertical)?

davemar
16th October 2009, 16:00
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.