I'm having trouble getting the actual background color of widgets. In my special case I'm having trouble with widgets within a QTabWidget.
This is on Windows7. So classic widgets have some greyish background, whereas widgets within a tab are generally drawn with a white background.
I tried:
def bgcolor(widget):
color = widget.palette().color(widget.backgroundRole()) # version 1
color = widget.palette().color(QtGui.QPalette.Background) # version 2
rgba = color.red(), color.green(), color.blue(), color.alpha()
return rgba
which is pretty much what I could figure out myself from the Qt documentation and what google and SO give. But, this just doesn't work.
I'm testing widgets inside and outside of a TabWidget and the function above returns identical colors for obviously differently colored widgets. Namely it always returns the greyish color, even for the plain white colored widgets within the tab.
Am I missing something here?
EDIT:
My problem is when using matplotlib, matplotlib draws figures with a "none" facecolor with the wrong background color when embedded in a QTabWidget: grey, even though the parent widget is white.
To fix this I wanted to get the background color of the widget and set it as background color for the figure. Though this may be a matplotlib issue, I guessed this would be the quickest workaround. As I noticed I couldn't get the proper color, I became insistent :)