PyQT5之设置窗口控件风格

设置窗口控件风格

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_())

posted @   星空28  阅读(47)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示