View Full Version : QTableview with flat header

21st June 2013, 19:15
I want to create a table with minimum space use. When I reduce the row size to minimum, the text in headers are not visible clearly as it has 3D shading. Other cells are fine with this row height as they are flat. Is there a way to make the Headers of the table Flat? After making headers FLAT, I Also need to change the header background to a different color. Advanced thanks for sample code for both :)

21st June 2013, 20:19
How about using styles? Applying any custom style to a widget immediately kills all the default visual effects. So doing something like this:

myTableWidget.setStyle("QHeaderView::section { border: 1px solid black}")

will give you tiny flat header. More info here (http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qheaderview)

22nd June 2013, 10:45
setStyle helped. But still the header view looks slightly different than other cells. Is there a way to exactly replicate the style of Other cells to header?

22nd June 2013, 12:19
Ah, so you are aiming for a maximum resemblance with the other cells. Then maybe try this style:

QHeaderView::section {
border-top: 0px solid grey;
border-bottom: 1px solid grey;
border-right: 1px solid grey;

You can experiment with styles in QtDesigner, by the way.