我尝试通过将Qt5中的样式表设置为空字符串来重置样式表。
这似乎适用于大多数小部件,但不适用于QDateEdit或QSpinBox之类的
。这是一个示例脚本:
import sys
from PySide2.QtWidgets import *
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.label = QLabel("FooBar")
self.edit = QLineEdit("Demo")
self.date = QDateEdit()
self.spin = QSpinBox()
self.button = QPushButton("reset style")
layout = QVBoxLayout()
layout.addWidget(self.label)
layout.addWidget(self.edit)
layout.addWidget(self.date)
layout.addWidget(self.spin)
layout.addWidget(self.button)
self.setLayout(layout)
self.setStyleSheet("Font: bold italic 30pt 'Comic Sans MS'")
self.button.clicked.connect(self.changeCSS)
def changeCSS(self):
self.setStyleSheet("")
if __name__ == "__main__":
app = QApplication(sys.argv)
form = Form()
form.show()
sys.exit(app.exec_())
当我单击“重置样式”按钮时,QLabel,QLineEdit和QPushButton更改回其默认设计,但QDateEdit和QSpinBox保留了先前样式表中的较大字体。
我还需要采取其他步骤将所有小部件恢复为默认设计吗?