[Interest] [QML] Is there a way to implement font.pointSize/font.pixelSize switch?
Ulf Hermann
ulf.hermann at qt.io
Tue Apr 14 08:47:37 CEST 2026
> This code can only switch a Label to use font.pixelSize from
> font.pointSize and can't switch it back.
>
> Is there a way to make it work? In other words, how do I reset
> font.pixelSize to an undefined value so it will use font.pointSize again?
>
> Label {
> text: "TEST"
> font.pointSize: cb.checked ? 0 : 13
> font.pixelSize: cb.checked ? 13 : 0
> }
This doesn't work because the two properties are not independent. We
also don't have a RESET accessor for either. Even if we had, the RESET
accessor would reset the value to some default which would still
conflict with the other property's setter.
What you can do, since font is a structured value type, is bind the
whole font instance:
font: cb.checked ? {pointSize: 13} : {pixelSize: 13)
best,
Ulf
More information about the Interest
mailing list