How can I set the font size of a TextField element in QML? wanna change size of the placeholderText
and also for the text which the user enters.
I tried with a lot of ways without luck!
TextField {
id: name_TextField; horizontalAlignment: Text.AlignHCenter;
Layout.preferredWidth: parentCLayer.width * 0.90; Layout.preferredHeight: 50
style: TextFieldStyle {
font.pixelSize: 20 // This doesn't seem to work either
}
placeholderText: qsTr("Your name here")
}
Using the
font
member of TextFieldThe
TextField
type itself has a memberfont
which contains an instance of the QML basic typefont
. It's sufficient to change the values of the inner-members of thefont
member ofTextField
to make the changes you want to see. Note that the color is provided by the TextField itself, not the font type.Default Style
Custom Style
Using the
style
member of TextFieldIf you want to do more in-depth styling of the
TextField
you can attach aTextFieldStyle
to thestyle
member of theTextField
. TheTextFieldStyle
instance also has afont
member, though in the IDE it will complain that font has no members if you reference them with dot notation, this may be bug QTCREATORBUG-11186. I believe the proper way to assign values is using group notation by referencing thefont
property with inner-items as such:It could be that bug #11186 is a genuine bug, or maybe by design the font property is TextFieldStyle is null; someone with better Qt/QML knowledge could provide a clearer answer as to that part of the question.
This guide on styling may help: http://wiki.qt.io/Qml_Styling
You can use the
style
property to customize yourTextField
. For example:I tried it and it works like a charm