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_())
复制代码

 

posted @   c语言我的最爱  阅读(858)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示