[PySide] conforming fonts between platforms
Frank Rueter | OHUfx
frank at ohufx.com
Mon Nov 11 21:20:01 CET 2013
I will give it a go (I'm on Ubunto as well at home)
On 11/11/13 20:48, Sean Fisk wrote:
> Hi Frank,
> I struggled with this a while ago
> and 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:
> |# fonts.py
> from PySideimport QtCore, QtGui
> def init():
> """Initialize embedded fonts."""
> font_dir_resource = QtCore.QResource(':/fonts')
> font_resource_path = font_dir_resource.absoluteFilePath()
> for ttf_filenamein 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
> # correctly.
> byte_array = res_file.readAll()
> And to use it (snippet):
> |class LoginView(QtGui.QDialog):
> def __init__(self, parent=None):
> super(LoginView, self).__init__(parent)
> # ...
> 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 you did!
> Sean Fisk
> On Mon, Nov 11, 2013 at 2:24 AM, Frank Rueter | OHUfx <frank at ohufx.com
> <mailto:frank at ohufx.com>> wrote:
> Hi all,
> I am facing the challenge I'm sure many of you have had to deal
> with before:
> 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
> What is the best practise here?
> Supposedly it is possible to compile a font into a resource which
> ensure almost identical results, right?! Has anybody ever done
> this before?
> PySide mailing list
> PySide at qt-project.org <mailto:PySide at qt-project.org>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PySide