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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM