Discussion:
[Development] Fonts in QtWidgets and QtQuick
Alberto Mardegan
2018-11-25 21:46:46 UTC
Permalink
Hi all!
I'm working on a desktop style for the QtQuick Controls 2 API [1], and
as I'm trying to achieve a pixel-by-pixel equivalence with QtWidgets,
I'm writing unit tests which graphically compare the output generated by
my controls versus that generated by QtWidgets.

I'm getting some issues with the fonts, for example in the buttons'
label: they just don't match, despite the fact that the QFont set on the
QPainter is exactly the same. For some reason, the lower levels of the
graphical stack (FontConfig, I presume) select a different font in
QtQuick, compared to the one used in QtWidgets.

The issue seems to go away if I run the tests under xvfb and specify a
different configuration file for FontConfig [2]. While this does the
trick, I'm left wondering whether (and where) QtWidgets somehow
initializes FontConfig differently from QtQuick. I guess I could get rid
of some hacks and truly achieve a pixel perfect replacement if I found
the way to replicate QtWidgets' font configuration in my QtQuick module.

Any ideas?

Ciao,
Alberto

[1]: https://gitlab.com/mardy/qqc2-desktop
[2]:
https://gitlab.com/mardy/qqc2-desktop/commit/caba6e67ce745d0653a10ccf8d801ad799129668
--
http://blog.mardy.it - Geek in un lingua international
Jean-Michaël Celerier
2018-11-25 21:32:30 UTC
Permalink
Did you enable native text rendering in Qt Quick ?

http://blog.qt.io/blog/2012/08/08/native-looking-text-in-qml-2/

best,
Jean-Michaël Celerier
http://www.jcelerier.name


On Sun, Nov 25, 2018 at 10:55 PM Alberto Mardegan <
Post by Alberto Mardegan
Hi all!
I'm working on a desktop style for the QtQuick Controls 2 API [1], and
as I'm trying to achieve a pixel-by-pixel equivalence with QtWidgets,
I'm writing unit tests which graphically compare the output generated by
my controls versus that generated by QtWidgets.
I'm getting some issues with the fonts, for example in the buttons'
label: they just don't match, despite the fact that the QFont set on the
QPainter is exactly the same. For some reason, the lower levels of the
graphical stack (FontConfig, I presume) select a different font in
QtQuick, compared to the one used in QtWidgets.
The issue seems to go away if I run the tests under xvfb and specify a
different configuration file for FontConfig [2]. While this does the
trick, I'm left wondering whether (and where) QtWidgets somehow
initializes FontConfig differently from QtQuick. I guess I could get rid
of some hacks and truly achieve a pixel perfect replacement if I found
the way to replicate QtWidgets' font configuration in my QtQuick module.
Any ideas?
Ciao,
Alberto
[1]: https://gitlab.com/mardy/qqc2-desktop
https://gitlab.com/mardy/qqc2-desktop/commit/caba6e67ce745d0653a10ccf8d801ad799129668
--
http://blog.mardy.it - Geek in un lingua international
_______________________________________________
Development mailing list
https://lists.qt-project.org/listinfo/development
Alberto Mardegan
2018-11-26 06:12:08 UTC
Permalink
Post by Jean-Michaël Celerier
Did you enable native text rendering in Qt Quick ?
I'm not using the QtQuick's Text element for rendering, but QStyle's
APIs on top of QPainter:

https://gitlab.com/mardy/qqc2-desktop/blob/master/plugin/styleitem.cpp#L1327

Ciao,
Alberto
--
http://blog.mardy.it - Geek in un lingua international
Tor Arne Vestbø
2018-11-25 22:45:47 UTC
Permalink
Have you set renderType to Text.NativeRendering ?

Tor Arne
Post by Alberto Mardegan
Hi all!
I'm working on a desktop style for the QtQuick Controls 2 API [1], and
as I'm trying to achieve a pixel-by-pixel equivalence with QtWidgets,
I'm writing unit tests which graphically compare the output generated by
my controls versus that generated by QtWidgets.
I'm getting some issues with the fonts, for example in the buttons'
label: they just don't match, despite the fact that the QFont set on the
QPainter is exactly the same. For some reason, the lower levels of the
graphical stack (FontConfig, I presume) select a different font in
QtQuick, compared to the one used in QtWidgets.
The issue seems to go away if I run the tests under xvfb and specify a
different configuration file for FontConfig [2]. While this does the
trick, I'm left wondering whether (and where) QtWidgets somehow
initializes FontConfig differently from QtQuick. I guess I could get rid
of some hacks and truly achieve a pixel perfect replacement if I found
the way to replicate QtWidgets' font configuration in my QtQuick module.
Any ideas?
Ciao,
Alberto
[1]: https://gitlab.com/mardy/qqc2-desktop
https://gitlab.com/mardy/qqc2-desktop/commit/caba6e67ce745d0653a10ccf8d801ad799129668
--
http://blog.mardy.it - Geek in un lingua international
_______________________________________________
Development mailing list
https://lists.qt-project.org/listinfo/development
Tor Arne Vestbø
2018-11-25 22:46:23 UTC
Permalink
Post by Tor Arne Vestbø
Have you set renderType to Text.NativeRendering ?
Sorry, too quick, you are using QPainter, NM 😊

Tor Arne
Post by Tor Arne Vestbø
Tor Arne
Post by Alberto Mardegan
Hi all!
I'm working on a desktop style for the QtQuick Controls 2 API [1], and
as I'm trying to achieve a pixel-by-pixel equivalence with QtWidgets,
I'm writing unit tests which graphically compare the output generated by
my controls versus that generated by QtWidgets.
I'm getting some issues with the fonts, for example in the buttons'
label: they just don't match, despite the fact that the QFont set on the
QPainter is exactly the same. For some reason, the lower levels of the
graphical stack (FontConfig, I presume) select a different font in
QtQuick, compared to the one used in QtWidgets.
The issue seems to go away if I run the tests under xvfb and specify a
different configuration file for FontConfig [2]. While this does the
trick, I'm left wondering whether (and where) QtWidgets somehow
initializes FontConfig differently from QtQuick. I guess I could get rid
of some hacks and truly achieve a pixel perfect replacement if I found
the way to replicate QtWidgets' font configuration in my QtQuick module.
Any ideas?
Ciao,
Alberto
[1]: https://gitlab.com/mardy/qqc2-desktop
https://gitlab.com/mardy/qqc2-desktop/commit/caba6e67ce745d0653a10ccf8d801ad799129668
--
http://blog.mardy.it - Geek in un lingua international
_______________________________________________
Development mailing list
https://lists.qt-project.org/listinfo/development
Alberto Mardegan
2018-11-27 21:18:01 UTC
Permalink
Post by Alberto Mardegan
I'm working on a desktop style for the QtQuick Controls 2 API [1], and
as I'm trying to achieve a pixel-by-pixel equivalence with QtWidgets,
I'm writing unit tests which graphically compare the output generated by
my controls versus that generated by QtWidgets.
Guess what? The font difference is due to the Qt::AA_Use96Dpi flag that
is set on the QApplication by the QTEST_MAIN() macro.
It looks like this flag is not properly handled by all code paths, so
setting it affects QtQuick's font rendering but not QtWidget's.

Anyway, setting this flag to `false` at the beginning of my tests seems
to fix the issue.

Ciao,
Alberto
--
http://blog.mardy.it - Geek in un lingua international
Loading...