Set default font for qml controls
-
I load my qml scene int QQuickWindow using this code:
QQmlComponent *comp = new QQmlComponent(engine, QUrl("qrc:/controllers/sample.qml"), contentItem()); QObject *obj = comp->create(); QQmlProperty::write(obj, "parent", QVariant::fromValue<QObject*>(contentItem()));
But font in labels and text fields is small. Is it possible to specify default font in qml?
-
Hi!
In main.cpp:QApplication app(argc, argv); // ... QFont fon("Helvetica", 40); app.setFont(fon);
-
Yeah, but this will affect fonts everywhere in application. Can I specify the font in my QQuickWindow only (that is subwindow in mdi area)?
-
I see no possibility to do it with QQuickWindow, but if you use a QWindow instead and place a QQuickWidget on it then you can use
QWidget::setStyleSheet()
to set the default font (and maybe other stuff as you like) only for that QQuickWidget.
:-) -
Thank you, I will try do it on native window container of my QQuickWindow
-
@Rem-Kolomna Did you check FontLoader ? You can add
FontLoader
insample.qml
to load a particular font and then use it to assign to different elements.