2017-04-23 138 views
0

我正在設置PySide(python)的簡單文本編輯器,我想設置默認字體,比方說,解放單聲道。我對改變字體不感興趣,所以我只需要爲主要對象設置一次字體。我會怎麼做?設置默認字體主窗口pyside

這是我寫來實現主窗口中的代碼:

class MainWindow(QMainWindow): 
    def __init__(self): 
     super(MainWindow, self).__init__() 
     self.initGUI() 

    def initGUI(self): 
     self.setWindowTitle("ScribblerSeq") 
     self.setWindowIcon(QIcon('./icon/appicon.png')) 
     self.setGeometry(1200, 1800, 800, 600) 
     self.statusLabel = QLabel('Showing Progress') 
     self.CreateProgessBar() 
     self.CreateStatusBar() 
     self.center() 
     self.SetupComponents() 
     self.show() 

謝謝

回答

1

使用樣式表:

main_window = MainWindow() 

CURRENT_PATH = os.path.dirname(__file__) 
style_path = os.path.join(CURRENT_PATH, 'style', 'app.css') 

# load and set stylesheet 
with open(style_path, "r") as fh: 
    main_window.setStyleSheet(fh.read()) 

app.css:

* { font-family: "Times New Roman", Times, serif;} 

使用分機的好處ernal樣式表文件就是你可以隨時添加的,如果你願意的話,可以稍後改變/添加東西。