设置默认字体主窗口pyside

时间:2017-04-23 09:04:23

标签: python fonts pyside

我正在使用PySide(python)设置一个简单的文本编辑器,我想设置默认字体,比如说,解放单声道。我对更改字体不感兴趣所以我只需要为主对象设置一次字体。我该怎么做?

这是我为实现主窗口而编写的代码:

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 个答案:

答案 0 :(得分: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;}

使用外部样式表文件的优点是,如果需要,您可以稍后添加更改/添加内容。