[PyQt] button color
David Boddie
david at boddie.org.uk
Mon Jul 16 19:15:32 BST 2007
On Mon Jul 16 18:49:21 BST 2007, Katja Wegner wrote:
> thanks for the fast answer. I checked the returned colors and all alpha
> values are 255, thus no semi-transparent colors.
I think I was confused about that as well, but that's another issue. :-/
> I checked it in my program, again:
> linux 4.2.1 (py2.4) = works fine
> windows 4.2.2 (py2.5) = only the border is changed but not the whole button
> (see attachment).
OK. I see. Just checking here, but:
* Are you using QPushButton or QToolButton?
* Are you changing the Button role or the Window role?
* Do the buttons change colour when they are clicked or highlighted?
> And I use button.palette() now.
OK. That's good. :-)
As a workaround, though it might make the buttons look less "native", you
could try giving them a style sheet by calling their setStyleSheet() methods
like this:
button.setStyleSheet(
"QPushButton { background-color: %s }"
"QPushButton:pressed { background-color: %s }" % (
color.name(), color.light(125).name()
)
)
where the actual colour is set accordingly. You probably don't need to call
setAutoFillBackground(True) on the button with this approach.
It would be good if changing the palette of the button just worked, but there
are plenty of style-dependent differences on each platform. The style sheet
approach is intended to be platform-independent.
David
More information about the PyQt
mailing list