【问题标题】:set default font main window pyside设置默认字体主窗口pyside
【发布时间】:2017-04-23 09:04:23
【问题描述】:

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

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

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

谢谢

【问题讨论】:

    标签: python fonts pyside


    【解决方案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;}
    

    使用外部样式表文件的优点是您可以在以后轻松添加更改/添加内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-13
      • 1970-01-01
      • 2011-04-15
      • 2012-07-24
      相关资源
      最近更新 更多