0

I'm writing a reusable font property, as described here and here. Here's my property

property font button2: Qt.font({
    family: defaultFont.name,
    styleName: "Bold",
    pointSize: 16
})

and here it how I use it, and it works fine

    Text {
        text: "button"
        font: MyFont.button2
    }

Now I would add the capitalization but adding it to the property like this

property font button2: Qt.font({
    family: defaultFont.name,
    styleName: "Bold",
    capitalization: "AllUppercase",
    pointSize: 16
})

It does not have effect at all. If I add it in the text component instead

    Text {
        text: "button"
        font: MyFont.button2
        font.capitalization: Font.AllUppercase
    }

it gives me a "Property has already been assigned a value" error.

How should I do that?

Moia
  • 2,216
  • 1
  • 12
  • 34

1 Answers1

0

If you want to change the capitalization then you must use it in Component.onCompleted:

Text {
    text: "button"
    font: MyFont.button2
    // font.capitalization: Font.AllUppercase
    Component.onCompleted: font.capitalization = Font.AllUppercase
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • I thought about that, but I had the impression it was a workaround and not the proper way to do that. There is actually no other way? – Moia May 20 '21 at 08:35
  • @Moia No, there is no way. Realize your logic: The binding is not sequential, that is, the property on the "N" line is not executed before the "N + 1" line, it may or may not. – eyllanesc May 20 '21 at 08:39
  • Soo are you saying I can't either putting it inside the Qt.font() function because the binding should happen after the object is constructed? – Moia May 20 '21 at 08:52