问题描述
我正在使用以下托盘类为我的窗口获取深色主题。然而有趣的是,当我使用 QtextEdit
时,它按预期工作,背景变为黑色,字体变为白色。但是当涉及到 QLineEdit
时,背景为白色,文本也为白色。你能告诉我这段代码的问题在哪里吗?我不想为每个表单都添加内联样式,因为我使用了太多的 QlineEdits
。非常感谢。
from PyQt5 import QtCore,QtGui,QtWidgets
import sys
from PyQt5.QtWidgets import QApplication,QMainWindow
from PyQt5.QtCore import QFile
from PyQt5.QtGui import QPalette,QColor,QPainter
from PyQt5.QtCore import *
from PyQt5.QtCore import Qt
import examiner
import MainLogin
#pallet
WHITE = QColor(255,255,255)
BLACK = QColor(0,0)
RED = QColor(255,0)
PRIMARY = QColor(53,53,53)
SECONDARY = QColor(35,35,35)
TERTIARY = QColor(42,130,218)
def css_rgb(color,a=False):
"""Get a CSS `rgb` or `rgba` string from a `QtGui.QColor`."""
return ("rgba({},{},{})" if a else "rgb({},{})").format(*color.getRgb())
class QDarkPalette(QPalette):
"""Dark palette for a Qt application meant to be used with the Fusion theme."""
def __init__(self,*__args):
super().__init__(*__args)
# Set all the colors based on the constants in globals
self.setColor(QPalette.Window,QColor(53,53))
self.setColor(QPalette.WindowText,Qt.white)
self.setColor(QPalette.Base,QColor(35,35))
self.setColor(QPalette.AlternateBase,53))
self.setColor(QPalette.ToolTipBase,QColor(25,25,25))
self.setColor(QPalette.ToolTipText,Qt.white)
self.setColor(QPalette.Text,Qt.white)
self.setColor(QPalette.Button,QColor(92,184,53))
self.setColor(QPalette.ButtonText,Qt.white)
self.setColor(QPalette.BrightText,Qt.red)
self.setColor(QPalette.Link,QColor(42,218))
self.setColor(QPalette.Highlight,218))
self.setColor(QPalette.HighlightedText,35))
self.setColor(QPalette.Active,QPalette.Button,53))
self.setColor(QPalette.disabled,QPalette.ButtonText,Qt.darkGray)
self.setColor(QPalette.disabled,QPalette.WindowText,QPalette.Text,QPalette.Light,53))
@staticmethod
def set_stylesheet(app):
"""Static method to set the tooltip stylesheet to a `QtWidgets.QApplication`."""
app.setStyleSheet("QToolTip {{"
"color: {white};"
"background-color: {tertiary};"
"border: 1px solid {white};"
"}}".format(white=css_rgb(WHITE),tertiary=css_rgb(TERTIARY)))
def set_app(self,app):
"""Set the Fusion theme and this palette to a `QtWidgets.QApplication`."""
app.setStyle("Fusion")
app.setPalette(self)
self.set_stylesheet(app)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)