[PySide] conforming fonts between platforms
Frank Rueter | OHUfx
frank at ohufx.com
Tue Nov 12 00:28:32 CET 2013
Actually, simply using setPixelSize and letting QT take care of the font
family does the job in my case even as a standalone, i.e.:
font = QApplication.font()
self.fontTitle = font
self.fontTitle.setPixelSize(12)
self.fontTitle.setBold(True)
self.fontSubTitle = QApplication.font()
self.fontSubTitle.setPixelSize(10)
self.fontSubTitle.setBold(False)
On 12/11/13 12:05, Frank Rueter | OHUfx wrote:
> Actually I realised that in my case I can simply inherit the system
> font, because my app is meant to run inside of another host app which
> is already doing the hard work with fonts.
> So in my case working with QApplication.font() magically solves all my
> troubles (inside the host app, not as a standalone).
>
> I will check in with the guys who wrote the host app to see if they
> can share the magic solution.
>
> Cheers,
> frank
>
>
> On 12/11/13 09:20, Frank Rueter | OHUfx wrote:
>> thanks Sean,
>>
>> 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
>>> <http://lists.qt-project.org/pipermail/pyside/2013-April/001252.html> 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.
>>> res_file.open(QtCore.QIODevice.ReadOnly)
>>> byte_array = res_file.readAll()
>>> QtGui.QFontDatabase.addApplicationFontFromData(byte_array)|
>>>
>>> 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_font.setStyleStrategy(QtGui.QFont.PreferAntialias)
>>> self.title_label = QtGui.QLabel('Your text in your font')
>>> self.title_label.setFont(self.title_font)|
>>>
>>> Hope this helps. And if you get it working on GNU/Linux, let me know
>>> what you did!
>>>
>>> Cheers,
>>>
>>> --
>>> 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
>>> 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?
>>>
>>> Cheers,
>>> frank
>>> _______________________________________________
>>> PySide mailing list
>>> PySide at qt-project.org <mailto:PySide at qt-project.org>
>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>
>>>
>>
>>
>>
>> _______________________________________________
>> PySide mailing list
>> PySide at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/pyside
>
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20131112/ce3ec005/attachment.html>
More information about the PySide
mailing list