首页
学习
活动
专区
圈层
工具
发布

python pyqt5 设置窗体风格

image.png

-- coding: utf-8 --

''' 【简介】 界面风格例子

'''

import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5 import QtCore from PyQt5.QtGui import *

class AppWidget(QWidget): def init(self, parent=None): super(AppWidget, self).init(parent) self.setWindowTitle("界面风格例子") horizontalLayout = QHBoxLayout() self.styleLabel = QLabel("Set Style:") self.styleComboBox = QComboBox() # 增加 styles 从 QStyleFactory self.styleComboBox.addItems(QStyleFactory.keys()) # 选择当前界面风格 index = self.styleComboBox.findText( QApplication.style().objectName(), QtCore.Qt.MatchFixedString) # 设置当前界面风格 self.styleComboBox.setCurrentIndex(index) # 通过comboBox选择界面分割 self.styleComboBox.activated[str].connect(self.handleStyleChanged) horizontalLayout.addWidget(self.styleLabel) horizontalLayout.addWidget(self.styleComboBox) self.setLayout(horizontalLayout)

代码语言:javascript
复制
# 改变界面风格
def handleStyleChanged(self, style):
    QApplication.setStyle(style)

if name == "main": app = QApplication(sys.argv) widgetApp = AppWidget() widgetApp.show() sys.exit(app.exec_())

QApplication.setStyle()

下一篇
举报
领券