K
K
kokapuk2021-02-11 23:19:50
PyQt
kokapuk, 2021-02-11 23:19:50

How to save fonts in pyqt5 program?

I have a program, it uses fonts from the Internet, not everyone has this font, so not everyone uses it in the program, how can I fix this?
How it should look like:
6025912ddc5f8093030811.png
How it looks to others:
602591450e04a784535985.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kokapuk, 2021-02-12
@kokapuk

Another hour of Google, and I still managed to find the answer, in order for the font to work we need: Download this font * .ttf and drop it into the folder with the program files, this is necessary in order to specify the exact path to font, regardless of the computer on which your application is installed, additional actions from the user are also not required. And so what we do:

app = QtWidgets.QApplication(sys.argv)
    myapp = Interface()
    myapp.show()
    sys.exit(app.exec_())

In this part of the code, where we have to render the window, we need to add our font to the base, the code will look like this:
app = QtWidgets.QApplication(sys.argv)
    QtGui.QFontDatabase.addApplicationFont(fr'путь к нашему шрифту')
    myapp = Interface()
    myapp.show()
    sys.exit(app.exec_())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question