gpt4 book ai didi

python - PyQt4 QPalette 不工作

转载 作者:行者123 更新时间:2023-11-28 17:38:10 24 4
gpt4 key购买 nike

    {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 角色来更改按钮颜色。

关于python - PyQt4 QPalette 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28257482/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com