How to get a QTableView to fill 100% of the width?

45,858

Solution 1

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.

Solution 2

Here works using only with:

ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);

I'm using Qt 5.2!

Share:
45,858
Admin
Author by

Admin

Updated on August 26, 2020

Comments

  • Admin
    Admin almost 4 years

    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?