当我在 CSS 中声明自定义属性(变量)时,运行应用程序时出现以下错误:
无法解析对象 Patrick 的样式表(0x73e4780)
这是我的代码:
import sys, re
from module.widgets import RuWidgets
from module.functions import *
from module.statics import *
from PySide2.QtGui import QFont, QFontDatabase, QIcon, QCursor
from PySide2.QtCore import Qt, Signal, QThread, QPoint, QSettings
from PySide2.QtWidgets import QApplication, QMainWindow, QFrame, QMenu, QLineEdit, QWidget
class Patrick(QMainWindow):
custom_colors = None
def __init__(self):
super().__init__()
data = readJSON(CONFIGURATION, 'data')
self.setWindowFlag(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.setWindowTitle(NAME)
self.setFixedSize(WIDTH, HEIGHT)
self.setStyleSheet(
"""
:root {
--dark: #483939;
--middle: #9C8181;
--light: #D9D9D9;
}
#normal {
background-color: var(--dark);
color: var(--light);
}
#inverted {
background-color: var(--light);
color: var(--dark);
}
.full_rounded {
border-radius: 8px, 8px, 8px, 8px;
}
.top_rounded {
border-radius: 0px, 0px, 8px, 8px;
}
::placeholder {
color: var(--middle);
}
"""
)
self.show()
background = QFrame()
background.setFixedSize(WIDTH, HEIGHT)
bar = QFrame()
bar.setFixedSize(WIDTH, WIDGET_HEIGHT)
for widget, object_name, object_class in [
(background, 'normal', 'full_rounded'),
(bar, 'inverted', 'top_rounded')
]:
widget.setObjectName(object_name)
widget.setProperty(object_class, True)
for widget in [
background,
bar
]:
self.layout().addWidget(widget)
if __name__ == '__main__':
application = QApplication(sys.argv)
window = Patrick()
#font = QFont(
# QFontDatabase.applicationFontFamilies(
# QFontDatabase.addApplicationFont(
# FONT.format('Inter-Regular')
# )
# )[0]
#)
#font.pointSize(FONT_SIZE)
#application.setFont(font)
application.exec_()
(请勿阅读:很抱歉必须在这里写下此内容,但如果我不添加更多有关我放入其中的代码量的文本,StackOverflow 不会让我问我的问题,所以我填补空间,希望没有问题)
我没有使用 PySide2 的经验,但如果它在解析你的 CSS 时遇到问题,那么你可以尝试用
:root
替换 html
,因为它们引用相同的元素。