Specifying font for many Text-elements in Qt QML

后端 未结 3 1114
遥遥无期
遥遥无期 2020-12-18 23:16

I have a widget specified through a QML file. This widget contains a top levelRectangle which contains two Columns. Each of these Columns

3条回答
  •  北海茫月
    2020-12-18 23:53

    In Qt 5.6 (at least, probably earlier too), you can use Qt.font() to dynamically allocate a font object and refer to it elsewhere. So, this works:

    property font myFont: Qt.font({
        family: fontfamily,
        bold: fontbold,
        italic: fontitalic,
        pixelSize: fontpixelsize
    });
    
    Text
    {   
        color: fontcolor
        font: parent.myFont
    }
    

    More info on Qt.font() here: https://doc-snapshots.qt.io/qt5-5.6/qml-qtqml-qt.html#font-method

提交回复
热议问题