Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt4 QPalette not working

    {btn = QtGui.QPushButton('Button', self)

    palettes = btn.palette()
    palettes.setColor(btn.backgroundRole(),QtCore.Qt.green)

    btn.setPalette(palettes)
    btn.setAutoFillBackground(True)}

Using btn.backgroundRole() only provides green border to the button.
Using btn.foregroundRole() changes the text color of the button
Using btn.windowRole() gives me error

TypeError: arguments did not match any overloaded call:
QPalette.setColor(QPalette.ColorGroup, QPalette.ColorRole, QColor): argument 1 has unexpected type 'str'
QPalette.setColor(QPalette.ColorRole, QColor): argument 1 has unexpected type 'str'

Tried QtGui.QPalette.Background in place of btn.windowRole() but does nothing
Also tried QtGui.QPalette.Base but does nothing
And also QtGui.QPalette.Window does nothing

How can I change button color using palettes?
I am unable to rectify the problem. I am using windows 7, PyQt4 and Python 3.4

like image 761
Freiza Avatar asked Dec 15 '25 13:12

Freiza


1 Answers

You can read in Qt documentation about QPalette :

Warning: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for both the Windows XP, Windows Vista, and the Mac OS X styles.

Windows 7 style also does not use palette colors for buttons. You should use stylesheets to give a color to your button. If you use some other theme than Windows 7 style, you can use QPalette.Button role to change the button color.

like image 148
Nejat Avatar answered Dec 18 '25 20:12

Nejat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!