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)
# 改變界面風格
def handleStyleChanged(self, style):
QApplication.setStyle(style)
複制
if name == "main":
app = QApplication(sys.argv)
widgetApp = AppWidget()
widgetApp.show()
sys.exit(app.exec_())