Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

font weights don't seem to change



  • Hi all -

    This code:

      Column {
          Text {
            font.family: 'roboto'
            font.pixelSize: 24
            font.weight: Font.Normal
            text: "this is an example of roboto with Font.Normal."
          }
          Text {
            font.family: 'roboto'
            font.pixelSize: 24
            font.weight: Font.Medium
            text: "this is an example of roboto with Font.Medium."
          }
          Text {
            font.family: 'roboto'
            font.pixelSize: 24
            font.weight: Font.DemiBold
            text: "this is an example of roboto with Font.DemiBold."
          }
          Text {
            font.family: 'roboto'
            font.pixelSize: 24
            font.weight: Font.Bold
            text: "this is an example of roboto with Font.Bold."
          }
    }
    

    Produces this:

    fonts.PNG

    Only two weights seem to be visible. Any ideas what's going wrong?

    Thanks...

    5.14.2, BTW.



  • @mzimmers Is this something the font has to explicitly support?



  • @fcarney said in font weights don't seem to change:

    @mzimmers Is this something the font has to explicitly support?

    Not sure I understand the question -- if the font doesn't support the weighting, how else would it be implemented?



  • Seems to be relevant to available fonts and what they support. No idea how this is determined.

    Column {
            id: fontcolumn
    
            anchors.right: parent.right
    
            //property string fontFam: 'roboto'
            property string fontFam: "Helvetica"
    
            Text {
                font.family: parent.fontFam
                font.pixelSize: 24
                font.weight: Font.Normal
                text: "this is an example of roboto with Font.Normal."
            }
            Text {
                font.family: parent.fontFam
                font.pixelSize: 24
                font.weight: Font.Medium
                text: "this is an example of roboto with Font.Medium."
            }
            Text {
                font.family: parent.fontFam
                font.pixelSize: 24
                font.weight: Font.DemiBold
                text: "this is an example of roboto with Font.DemiBold."
            }
            Text {
                font.family: parent.fontFam
                font.pixelSize: 24
                font.weight: Font.Bold
                text: "this is an example of roboto with Font.Bold."
            }
        }
    
        ListView {
            anchors.top: fontcolumn.bottom
            anchors.bottom: parent.bottom
            anchors.right: parent.right
    
            width: 200
    
            model: Qt.fontFamilies()
    
            delegate: Item {
                height: 40;
                width: ListView.view.width
                Text {
                    text: modelData;
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            fontcolumn.fontFam = modelData
                        }
                    }
                }
            }
        }
    

    You will need to re-anchor these Items to see this correctly. It gives you a list of available fonts and selects them when you click on the font name in the list.



  • @fcarney interesting...on my system, none of the available fonts produced more than 2 distinct weights; some only showed 1. Is this consistent with your findings?



  • @mzimmers I think I saw one with 3 diff values. The rest were 2.



  • So, this is an area I know little about; who is to "blame" for the lack of more weight options?



  • I suspect if you provided ttf font it might work better. No idea if the system fonts are ttf. Also, adding fonts in Windows is a pain as you have to install them I suppose you could hide a font in a qrc resource. But Windows does weird things with fonts I don't completely understand.



  • I'm running on Linux (actually WSL)...that might be part of the problem, though you said it wasn't working for you, either.

    So, do I infer correctly that there's a process for manually adding fonts to Qt?


Log in to reply