PDA

View Full Version : Transparent QHeaderView



paul888
8th July 2017, 08:44
Hi,

I want to have a transparent HeaderView by reimplementing the paintSection method.

No Problem with stylesheet
setStyleSheet("QHeaderView::section {border: none; background-color: transparent;} QHeaderView {border: none; background-color: transparent;}");

But I have no idea how to do it in paintSelection.

Please help me out.

Rajesh.Rathod
20th July 2017, 07:53
If I understood your requirement correctly then you should set your header height to zero, and start your table view just below the point from where your cell area starts.

Or your transparent headers does anything which will not work in above case.

Please describe your requirement and may be some trick will work here.

paul888
21st July 2017, 07:58
I have a custom TableView that should have the header part.
The TableView should have transparent background: the header- as well as the cell area.

I am able to change the background color of the header part by subclassing the HeaderView class and reimplementing the paintSection method, but not to transparent.

So far I use setStyleSheet method to have transparent header part. However, I am quite sure that there is a way or some trick to do that by reimplementing the paintSection of custom HeaderView class.

Rajesh.Rathod
24th July 2017, 10:00
Hi,

If you will upload some screenshot then it will help to understand what exactly you are looking for.

Thanks,

d_stranz
24th July 2017, 18:45
However, I am quite sure that there is a way or some trick to do that by reimplementing the paintSection of custom HeaderView class.

You might try changing the QPainter::CompositionMode. I think the real problem is probably that the QHeaderView clears the section rect and fills it with the background color before it calls paintSection() so anything that might have been there from whatever is underneath has been erased.

You could try setting the QWidget property autoFillBackground to false when you create the QHeaderView instance (or retrieve it from the QTableView). This changes the default behavior (erase and fill with the background color) to do nothing. You may not need to derive a custom class from QHeaderView.