How to Remove the Header in QTableView?
12,594
Solution 1
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();
Solution 2
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;}");
Author by
New Moon
Updated on July 22, 2022Comments
-
New Moon almost 2 years
As shown in the Image below, How can i remove the unwanted header section ?
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).
-
New Moon almost 11 yearsYes.. that's what i want. But, I just want to know, Is there anyother way of removing the Header section.
-
thuga almost 11 years@NewMoon I don't think there is anything that is simpler than hiding it with a style sheet. You'd probably have to resize the header so it's the same width as the total width of your columns. If your columns are set to fixed width, then it is fairly simple, but I'd still go with the style sheets.
-
Dmitry Sazonov almost 11 years@NewMoon if you are not looking for easy ways, you may create your own widget, based on QHeaderView
-
Michael Scheper about 8 years@thuga: I think NewMoon might want to remove the header altogether, in which case, there is a simpler way than with a style sheet: stackoverflow.com/a/37994662/1450294
-
thuga almost 8 years@MichaelScheper No. In his question he highlighted only the stretched section, and he stated Please Help to remove the Header Section which is displaying after the 4th column (Header section which is highlighted).
-
Michael Scheper almost 8 years@thuga: Hmmm, yes, you're right. I think this is called not seeing the forest for the trees. ☺
-
Sturm almost 5 yearsRequires
#include <QHeaderView>