gpt4 book ai didi

python - 在Python中更改Widget Window的样式和背景颜色

转载 作者:太空宇宙 更新时间:2023-11-03 21:23:43 30 4
gpt4 key购买 nike

enter image description here

def color_picker(self):
color = QtGui.QColorDialog.getColor()
self.setStyleSheet("QWidget { background-color: %s}" % color.name())
global selectedcolor
selectedcolor=color.name()
print(selectedcolor)
global RGBcolorfromcolorpicker
RGBcolorfromcolorpicker=selectedcolor.lstrip('#')

#This line doesn't work.
self.QColorDialog.setStyleSheet('QTabBar::tab{background-color: red;}')

self.send_rgb_color()

最佳答案

您可以使用类的对象,而不是仅使用静态方法,在本例中,我创建了一个已经实现更改颜色功能的类:

from PyQt4 import QtCore, QtGui

class ColorDialog(QtGui.QColorDialog):
def __init__(self, initial=QtGui.QColor(), parent=None):
super(ColorDialog, self).__init__(parent)
self.setOption(QtGui.QColorDialog.DontUseNativeDialog)
self.currentColorChanged.connect(self.onCurrentColorChanged)
self.onCurrentColorChanged(self.currentColor())

@QtCore.pyqtSlot(QtGui.QColor)
def onCurrentColorChanged(self, color):
self.setStyleSheet("QColorDialog { background-color: %s}" % color.name())

if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
w = ColorDialog()
if w.exec_() == QtGui.QDialog.Accepted:
print(w.currentColor())

关于python - 在Python中更改Widget Window的样式和背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54011012/

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