How to receive the default value of e.g. TextEdit font.pointerSize
?
I would like to create a custom widget that uses some default values but allows to set some values from outside. Therefore it is necessary - as far as I know - to add a property
variable that is accessible from outside (in this example it's fontPointerSize
). I want this default property to be the default of an existing QML widget.
main.qml
import QtQuick 2.0
Rectangle {
id: background;
color: "white";
width: 200;
height: 200;
MyWidget {
id: widget
// fontPointerSize: 14
anchors.topMargin: 8
anchors.top: picker.bottom
}
}
MyWidget.qml
import QtQuick 2.0
Rectangle {
width: 100
height: 26
color: "orange"
// how to get Text font.pointerSize default?
property real fontPointerSize: 11
Text {
id: name
text: qsTr("hello world")
font.pointSize: fontPointerSize
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
You want to use a property alias. In MyWidget.qml, use
Then, the
fontPointerSize
property will be thefont.pointSize
property of theText
element, and thus will start off with the default value.