QApplication.setStyle()函数详细教程


Pyside6.QtWidgets.QApplication类的成员函数setStyle()用于设置程序的GUI样式;

示例代码

import sys
from PySide6.QtWidgets import QApplication,QWidget,QPushButton,QVBoxLayout,QStyleFactory
from PySide6.QtCore import Slot

class MyWidget(QWidget):
    def __init__(self):
        super().__init__()

        self.button = QPushButton("改变Style")
        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.button)
        self.button.clicked.connect(self.changeStyle)

    @Slot()
    def changeStyle(self):
        app.setStyle(QStyleFactory.create("Fusion"))

app = QApplication([])


widget = MyWidget()
widget.resize(300, 200)
widget.show()
sys.exit(app.exec())

运行效果

pyside6 setStyle

更详细资料,请参考PySide6改变界面主题风格

如需转载,请注明出处;本文地址:https://www.perfcode.com/p/pyside6-qtwidgets-qapplication-setstyle.html