[Interest] Cross-platform font normalization best practice
Hamish Moffatt
hamish at risingsoftware.com
Thu May 14 04:06:51 CEST 2015
On 13/05/15 22:06, Bob Hood wrote:
>
> So, to make OS X look close to the Windows default settings, I have to
> use a font and/or size that is different than the OS X default
> settings. This entails manually changing at runtime. I was wondering
> if there was a built-in mechanism for handling that.
>
> Adding a platform-specific section to the MainWindow constructor, just
> following the setupUi() call, appears to achieve what I'm after:
>
> ui->setupUi(this);
>
> #ifdef _MACOS
> // this normalizes the appearance of the dialog to look more like
> Windows.
> this->setStyleSheet("font: 11pt \"Lucida Grande\";");
> ui->label_Intro_Line_1->setStyleSheet("font: 18pt \"Tahoma\";");
> ui->label_Intro_Line_2->setStyleSheet("font: 18pt \"Tahoma\";");
> #endif
>
>
> But it just feels clunky to me, since changes to the default Windows
> settings in the *.ui file will require modification of the separate
> C++ code to match. Having platform-specific sections in the *.ui file
> itself would seem to be a more elegant approach.
>
Maybe you could set up font substitutions (QFont::insertSubstitution())
from a generic name to a different real font on each platform, and then
use that generic name in your stylesheet/code instead? (I haven't tried
this.)
Alternatively, if you just want one font throughout, or mostly
throughout, you can set it as your default font with
QApplication::setFont(), then don't specify the font names at all in
your style sheets. This is what we're doing here, although we do use the
same font on both platforms.
Hamish
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150514/f1bd6e77/attachment.html>
More information about the Interest
mailing list