My application loses the typographical font when executing it in another pc, QT creator, c ++

0

I have created an application with Qt creator in which I use a font that is not standard for window. After doing deploy and executing it in another PC, the typographic font of the whole text changes and this damages a lot in terms of the visual aspect of the application.

What do I have to do so that windeployqt.exe detects the source that I am using in the application and includes it within the deploy, and so it is seen in other pcs?

    
asked by HOLDTHEDOOR 16.10.2018 в 19:31
source

1 answer

4

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';
    
answered by 17.10.2018 / 06:52
source