Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out which fonts are available in qml?

Tags:

qt

qml

qtquick2

I would like to know which fonts I can use in a QML environment for the font.family property. Are these fonts system-specific or are they built into the framework? Is there any way to list all available fonts?

like image 270
FourtyTwo Avatar asked Jul 21 '14 07:07

FourtyTwo


4 Answers

This code will list all the accepted font families:

ListView {
    anchors.fill: parent; 
    model: Qt.fontFamilies()

    delegate: Item {
        height: 40; 
        width: ListView.view.width
        Text {
            anchors.centerIn: parent
            text: modelData; 
        }
    }
}
like image 165
Mido Avatar answered Oct 17 '22 07:10

Mido


You can improve the previous answer by adding this

Text {
     font.family: modelData
     anchors.centerIn: parent
     text: modelData;
}
like image 30
Gaël Porté Avatar answered Oct 06 '22 18:10

Gaël Porté


The fonts are system-specific so you should see what your system proposes.

If you are using QtCreator :

try putting your mouse over the end of your component name

Text <here> {
    ...
}

You should see a yellow light, click on it and you'll have an interface that allows to choose the font.

You can also access the interface with ctrl + alt + space while inside the component. Or with right click.

like image 12
BlueMagma Avatar answered Oct 17 '22 06:10

BlueMagma


This is a system-specific list of fonts, but you can specify external font from resources (QRC)

like image 4
Dcow Avatar answered Oct 17 '22 08:10

Dcow