You have two possibilities:
-
You attach the source as a resource (you add it to the .qrc file). If you do this you will have to indicate that the source is found as an embedded resource, which slightly changes the way to locate it:
int id = QFontDatabase::addApplicationFont(":/fonts/mifuentepersonalizada.ttf");
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
QFont miFuente(family);
-
You install the source on the computers where you are going to run the application. You can do this by hand, with a script inside your application or by creating an installer for the application. In this case, the source load does not change with respect to your original code.
Edit:
Steps to load the source:
add the source to qt
The first thing is to make sure that Qt loads the source. To do this, simply add this line:
QFontDatabase::addApplicationFont(“:/fonts/fuente-regular.ttf”);
Where fonts/mi_fuente.ttf
is the resource path.
This line can be put, for example, in the constructor of the main window or at some point of the initialization.
use the source
To use the font from the stylesheet we can use the following:
font: 18pt 'fuente';