How to Remove the Header in QTableView?

18.2k Views Asked by At

As shown in the Image below, How can i remove the unwanted header section ?

QTableView with 4 columns

My Table has to display only 4 column headers. It should not display the whole header section. Please Help to remove the Header Section which is displaying after the 4th column (Header section which is highlighted).

2

There are 2 best solutions below

6
On

You can stretch the last column to take all the avaiable space using the stretchLastSection property:

myTable->horizontalHeader()->setStretchLastSection(true);

Or you can hide it with a stylesheet:

myTable->setStyleSheet("QHeaderView {background-color: transparent;}");
1
On

From your comments in the other answer, I wonder if, by 'it should not display the whole header section', you mean you want to remove the header altogether.

If so, here's how:

myTable->horizontalHeader()->hide();