PyQt4 QPalette 不工作
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)}
使用 btn.backgroundRole()
只为按钮提供绿色边框。
使用 btn.foregroundRole()
更改按钮的文本颜色
使用 btn.windowRole()
给我错误
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'
尝试用 QtGui.QPalette.Background
代替 btn.windowRole()
但什么也没做
也试过 QtGui.QPalette.Base
但什么也没做
而且 QtGui.QPalette.Window
什么都不做
如何使用调色板更改按钮颜色?
我无法纠正这个问题。我正在使用 windows 7、PyQt4 和 Python 3.4
您可以阅读有关 QPalette
的 Qt 文档:
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 样式也不对按钮使用调色板颜色。您应该使用样式表为按钮指定颜色。如果您使用 Windows 7 样式以外的其他主题,您可以使用 QPalette.Button
角色来更改按钮颜色。
{btn = QtGui.QPushButton('Button', self)
palettes = btn.palette()
palettes.setColor(btn.backgroundRole(),QtCore.Qt.green)
btn.setPalette(palettes)
btn.setAutoFillBackground(True)}
使用 btn.backgroundRole()
只为按钮提供绿色边框。
使用 btn.foregroundRole()
更改按钮的文本颜色
使用 btn.windowRole()
给我错误
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'
尝试用 QtGui.QPalette.Background
代替 btn.windowRole()
但什么也没做
也试过 QtGui.QPalette.Base
但什么也没做
而且 QtGui.QPalette.Window
什么都不做
如何使用调色板更改按钮颜色?
我无法纠正这个问题。我正在使用 windows 7、PyQt4 和 Python 3.4
您可以阅读有关 QPalette
的 Qt 文档:
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 样式也不对按钮使用调色板颜色。您应该使用样式表为按钮指定颜色。如果您使用 Windows 7 样式以外的其他主题,您可以使用 QPalette.Button
角色来更改按钮颜色。