Here's a print screen of my software:
As you can see, the first QTableVIew
headers do not take 100% of the width. In fact, there is a small vertical white space on the right of the field size
.
How can I get the headers to take 100% of the width of the QTableView
?
Use
view->horizontalHeader()->setStretchLastSection(true)
to make the last column expand to free space.Additionally, use
view->horizontalHeader()->setResizeMode(QHeaderView::Stretch)
to give columns the same width.If you are using Qt 5,
QHeaderView::setResizeMode()
is no longer available. Instead, you can useQHeaderView::setSectionResizeMode()
. Just call it for every column:Here works using only with:
I'm using Qt 5.2!
I had a hard time distributing column widths among all cells of a table. In my case, in headerData function of the model, I did the following (requires calling resizeColumnsToContents() somewhere):