[PySide] conforming fonts between platforms
sean at seanfisk.com
Mon Nov 11 08:48:01 CET 2013
I struggled with this a while
have it working on Windows and Mac OS X. Still having some problems on
GNU/Linux (specifically targeting Ubuntu) but my team is working on it. We
first compile some TTF files into our resources, then import them in our
program, then call this:
from PySide import QtCore, QtGui
"""Initialize embedded fonts."""
font_dir_resource = QtCore.QResource(':/fonts')
font_resource_path = font_dir_resource.absoluteFilePath()
for ttf_filename in font_dir_resource.children():
# DON'T use `os.path.join()' here because Qt always uses UNIX-style
# paths. On Windows `os.sep' is '\\'.
res_file = QtCore.QFile('/'.join([font_resource_path, ttf_filename]))
# Must re-open the file in read-only mode to read the contents
byte_array = res_file.readAll()
And to use it (snippet):
def __init__(self, parent=None):
self.title_font = QtGui.QFont('YourFontName', 46)
self.title_label = QtGui.QLabel('Your text in your font')
Hope this helps. And if you get it working on GNU/Linux, let me know what
On Mon, Nov 11, 2013 at 2:24 AM, Frank Rueter | OHUfx <frank at ohufx.com>wrote:
> Hi all,
> I am facing the challenge I'm sure many of you have had to deal with
> I need to make sure that the font used in my application looks as
> similar as posisble between windows, linux and osx.
> I am currently using 12 point Helvetica, which turns into a 16 pixel
> high Sans Nimbus L on my linux box messing up my custom widget's layouts.
> What is the best practise here?
> Supposedly it is possible to compile a font into a resource which would
> ensure almost identical results, right?! Has anybody ever done this before?
> PySide mailing list
> PySide at qt-project.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PySide