PDA

View Full Version : Tabified QDockWidget, QTabWidget, and Style Sheets



prof.ebral
6th December 2012, 15:13
I've run into a problem. I have a QTabWidget inside a QDockWidget. My QMainWindow class allows for tabified QDockWidgets. My problem is setting the style sheet for the QTabBar and QTabWidget. I want to style the QDockWidget tabs differently but the QTabWidget inside the QDockWidget uses both the style I set for the QDockWidget it is in as well as the style sheet I set for it.

I thought I may be able to correct this behavior if I reclassed the QTabBar the QMainWindow class uses for tabified QDockWidgets, however I cannot find a way the QMainWindow class creates it. There is a QTabBar that shows as one of the children of my QMainWindow class.

By reclassing the classes I would be able to use the new variable name for the style sheets and I think this would prevent my overrun problem. Without it I am stuck using the base QTabBar as a style sheet reference.

Can anyone help with this? Perhaps there is another way to style the QDockWidget tabs seperately from a contained QTabWidget.

prof.ebral
7th December 2012, 17:49
Well ... this seems a bit unfair for developers. The QTabBar is private and I cannot reclass it. However I did find a work around. In PyQt it looks something like this

In the QMainWindow class



for c in self.children():
if isinstance(c, QTabBar):
style = theme.getStyle()
c.setStyleSheet(style); break


I would appreciate it if Qt gave us access to the event that creates the QTabBar so we can handle it better. In the meantime this works because the QDockWidget parent doesn't receive the styles for QTabBar and QTabWidget.