<div dir="ltr"><div class="markdown-here-wrapper" id="markdown-here-wrapper-569912" style><p style="margin:1.2em 0px!important">Hi Frank,</p>
<p style="margin:1.2em 0px!important">I struggled with this <a href="http://lists.qt-project.org/pipermail/pyside/2013-April/001252.html">a while ago</a> 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:</p>


<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="language-python" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline;white-space:pre;overflow:auto;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block;padding:0.5em;color:rgb(51,51,51);background-color:rgb(248,248,255);background-repeat:initial initial"><span class="comment" style="color:rgb(153,153,136);font-style:italic"># fonts.py</span>

<span class="keyword" style="color:rgb(51,51,51);font-weight:bold">from</span> PySide <span class="keyword" style="color:rgb(51,51,51);font-weight:bold">import</span> QtCore, QtGui

<span class="function"><span class="keyword" style="color:rgb(51,51,51);font-weight:bold">def</span> <span class="title" style="color:rgb(153,0,0);font-weight:bold">init</span><span class="params">()</span>:</span>
    <span class="string" style="color:rgb(221,17,68)">"""Initialize embedded fonts."""</span>
    font_dir_resource = QtCore.QResource(<span class="string" style="color:rgb(221,17,68)">':/fonts'</span>)
    font_resource_path = font_dir_resource.absoluteFilePath()
    <span class="keyword" style="color:rgb(51,51,51);font-weight:bold">for</span> ttf_filename <span class="keyword" style="color:rgb(51,51,51);font-weight:bold">in</span> font_dir_resource.children():
        <span class="comment" style="color:rgb(153,153,136);font-style:italic"># DON'T use `os.path.join()' here because Qt always uses UNIX-style</span>
        <span class="comment" style="color:rgb(153,153,136);font-style:italic"># paths. On Windows `os.sep' is '\\'.</span>
        res_file = QtCore.QFile(<span class="string" style="color:rgb(221,17,68)">'/'</span>.join([font_resource_path, ttf_filename]))
        <span class="comment" style="color:rgb(153,153,136);font-style:italic"># Must re-open the file in read-only mode to read the contents</span>
        <span class="comment" style="color:rgb(153,153,136);font-style:italic"># correctly.</span>
        res_file.open(QtCore.QIODevice.ReadOnly)
        byte_array = res_file.readAll()
        QtGui.QFontDatabase.addApplicationFontFromData(byte_array)</code></pre>
<p style="margin:1.2em 0px!important">And to use it (snippet):</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="language-python" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline;white-space:pre;overflow:auto;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block;padding:0.5em;color:rgb(51,51,51);background-color:rgb(248,248,255);background-repeat:initial initial"><span class="class" style="color:rgb(68,85,136);font-weight:bold"><span class="keyword" style="color:rgb(51,51,51);font-weight:bold">class</span> <span class="title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">LoginView</span><span class="params">(QtGui.QDialog)</span>:</span>
    <span class="function"><span class="keyword" style="color:rgb(51,51,51);font-weight:bold">def</span> <span class="title" style="color:rgb(153,0,0);font-weight:bold">__init__</span><span class="params">(self, parent=None)</span>:</span>
        super(LoginView, self).__init__(parent)

        <span class="comment" style="color:rgb(153,153,136);font-style:italic"># ...</span>
        self.title_font = QtGui.QFont(<span class="string" style="color:rgb(221,17,68)">'YourFontName'</span>, <span class="number" style="color:rgb(0,153,153)">46</span>)
        self.title_font.setStyleStrategy(QtGui.QFont.PreferAntialias)
        self.title_label = QtGui.QLabel(<span class="string" style="color:rgb(221,17,68)">'Your text in your font'</span>)
        self.title_label.setFont(self.title_font)</code></pre>
<p style="margin:1.2em 0px!important">Hope this helps. And if you get it working on GNU/Linux, let me know what you did!</p>
<p style="margin:1.2em 0px!important">Cheers,</p></div><div class="gmail_extra"><div><div>--</div><div>Sean Fisk</div></div>
<br><br><div class="gmail_quote">On Mon, Nov 11, 2013 at 2:24 AM, Frank Rueter | OHUfx <span dir="ltr"><<a href="mailto:frank@ohufx.com" target="_blank">frank@ohufx.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

Hi all,<br>
<br>
I am facing the challenge I'm sure many of you have had to deal with before:<br>
<br>
I need to make sure that the font used in my application looks as<br>
similar as posisble between windows, linux and osx.<br>
<br>
I am currently using 12 point Helvetica, which turns into a 16 pixel<br>
high Sans Nimbus L on my linux box messing up my custom widget's layouts.<br>
<br>
What is the best practise here?<br>
Supposedly it is possible to compile a font into a resource which would<br>
ensure almost identical results, right?! Has anybody ever done this before?<br>
<br>
Cheers,<br>
frank<br>
_______________________________________________<br>
PySide mailing list<br>
<a href="mailto:PySide@qt-project.org">PySide@qt-project.org</a><br>
<a href="http://lists.qt-project.org/mailman/listinfo/pyside" target="_blank">http://lists.qt-project.org/mailman/listinfo/pyside</a><br>
</blockquote></div></div><div class="gmail_extra"><br></div></div>