Reputation: 4664
There is a way to get Font family that was resolved to in Qml https://doc-snapshots.qt.io/qt5-5.9/qml-qtquick-text.html#fontInfo.family-prop
However this property is available only from Qt5.9, how can we get this info for older versions (Qt 5.4 to be precise)
Upvotes: 2
Views: 491
Reputation: 7150
The way this is done in Qt 5.9 and later is via embedding a QFontInfo
in the Text
object and returning a JS object to the QML with all relevant fields of the QFontInfo
as keys of the object.
How I would add this in previous version is by creating a new QObject
class with a Q_INVOKABLE QVariantMap fontInfo(const QFont& font)
.
This function would construct a QFontInfo
from the font, and fill the QVariantMap
with the relevant info you need.
Register it to be able to use it in QML with qmlRegisterSingletonType()
.
And then you could use it like that in QML :
Text {
property var fontInfo: FontUtils.fontInfo(font)
}
Upvotes: 2