PyQt5基础学习-QApplication.setStyle(设置窗口的风格) 1.QComboBox().actived[str].connect(下拉列表变化时的函数)
通过下拉列表的选择来进行窗口的设置
WindowStyle.py
""" 窗口, 绘图与特效:设置窗口控件风格 QApplication.setStyle(...) """ import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5 import QtCore from PyQt5.QtGui import * class WindowStyle(QWidget): def __init__(self): super(WindowStyle, self).__init__() self.setWindowTitle("设置窗口风格") horizontalLayout = QHBoxLayout() self.styleLabel = QLabel("设置窗口风格") self.styleComboBox = QComboBox() self.styleComboBox.addItems(QStyleFactory.keys()) #将选项变为当前的风格库里面的数据 #获得当前窗口的风格 print(QApplication.style().objectName()) index = self.styleComboBox.findText(QApplication.style().objectName(), Qt.MatchFixedString) #找出当前窗口风格的id self.styleComboBox.setCurrentIndex(index) #将下拉列表显示为当前窗口的内容 self.styleComboBox.activated[str].connect(self.handleStyleChanged) # 如果styleComboBox发生变化 horizontalLayout.addWidget(self.styleLabel) horizontalLayout.addWidget(self.styleComboBox) self.setLayout(horizontalLayout) def handleStyleChanged(self, style): QApplication.setStyle(style) #传入变化的QStyleFactory.keys() if __name__ == "__main__": app = QApplication(sys.argv) main = WindowStyle() main.show() sys.exit(app.exec_())
每天更新pyQt5内容