Use a Specific Font

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Cuq
Posts: 145
Joined: Tue Jul 06, 2021 10:07 am

Use a Specific Font

Post by Cuq »

Hello,

I'm need to use a specific font in a workbench. I did not find any example in the existing Workbenchs of declaration or use of a font in a Python code. Would someone have a start of track to integrate this font?

Thanks a lot

Cuq
chrisb
Veteran
Posts: 53920
Joined: Tue Mar 17, 2015 9:14 am

Re: Use a Specific Font

Post by chrisb »

Moved from Developers forum.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Use a Specific Font

Post by onekk »

Cuq wrote: Wed Mar 22, 2023 1:22 pm Hello,

I'm need to use a specific font in a workbench. I did not find any example in the existing Workbenchs of declaration or use of a font in a Python code. Would someone have a start of track to integrate this font?

Thanks a lot

Cuq
Please explain better, you could not change a font used in UI for a specific WB, they are mostly set using Qt stylesheet, if not you have to make by hand all your WB GUI and assign to each widget a specific font and size.

If you want to use a font for other uses it is another matter.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Use a Specific Font

Post by Roy_043 »

See: viewtopic.php?t=75573&start=30#p657250

Code: Select all

fontFile = App.getResourceDir() + "Mod/TechDraw/Resources/fonts/osifont-lgpl3fe.ttf"
fontId = QtGui.QFontDatabase.addApplicationFont(fontFile)
User avatar
Cuq
Posts: 145
Joined: Tue Jul 06, 2021 10:07 am

Re: Use a Specific Font

Post by Cuq »

Thank you so much @Roy_043 works Like a charm :

Code: Select all

    def __init__(self):
        "This function is executed when FreeCAD starts"
        from PySide import QtGui
        fontFile = os.path.join(FreeCAD.getResourceDir(), "Mod", "TechDraw", "Resources", "fonts", "osifont-lgpl3fe.ttf")
        fontId = QtGui.QFontDatabase.addApplicationFont(fontFile)
        FreeCAD.Console.PrintMessage("{} Added as QtGui Font Id : {}\n".format(fontFile,fontId))
        pass
Post Reply