设置窗口控件风格
QApplication.setStyle(...)
窗口可以显示三种风格:['windowsvista', 'Windows', 'Fusion']
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
# print(QStyleFactory.keys())
class WindowStyle(QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.resize(400, 100)
self.setWindowTitle("设置窗口风格")
self.styleLabel = QLabel("设置窗口风格:")
self.styleComboBox = QComboBox()
self.styleComboBox.addItems(QStyleFactory.keys())
# 获取当前窗口风格
print(QApplication.style().objectName())
index = self.styleComboBox.findText(QApplication.style().objectName(), Qt.MatchFixedString)
self.styleComboBox.setCurrentIndex(index)
self.styleComboBox.activated[str].connect(self.handleStyleChanged)
horizontaLayout = QHBoxLayout()
horizontaLayout.addWidget(self.styleLabel)
horizontaLayout.addWidget(self.styleComboBox)
self.setLayout(horizontaLayout)
def handleStyleChanged(self, style):
QApplication.setStyle(style)
if __name__ == "__main__":
app = QApplication(sys.argv)
main = WindowStyle()
main.show()
sys.exit(app.exec_())
标签:__,控件,style,窗口,self,QApplication,PyQT5,styleComboBox
From: https://www.cnblogs.com/jackchen28/p/18239572