我制作了自定义元素DataField
。
当我将它放在表单上的Qt Designer(另一个qml文件)中时,我的道具的值为零。如何为自定义属性设置非零值?
我喜欢这样:ratio
,pixelSize
等默认情况下不为零。
//DataField.qml
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.3
import QtQuick.Window 2.1
Item {
id: field
width: 100
height: 100
property bool readOnly: true
readonly property real ratio: Screen.height / 1200
property real size: 20
property real cellRatio: 1.25
readonly property real pixelSize: field.size * field.ratio
readonly property real cellHeight: field.size * field.cellRatio
property real bottom
property real top
property int decimals
property string top_text: "Up"
property string left_text: "Left"
property string right_text: "Right"
property string value_text: "23"
Label {
id: top_lbl
x: -69
y: -31
height: Props.cellHeight
horizontalAlignment: Text.AlignLeft
font.pixelSize: field.pixelSize
verticalAlignment: Text.AlignVCenter
text: field.top_text
}
TextField {
id: textField1
y: 31
width: 90
height: field.cellHeight
text: field.value_text
anchors.verticalCenter: left_lbl.verticalCenter
horizontalAlignment: TextInput.AlignRight
validator: DoubleValidator {
decimals: field.decimals
notation: DoubleValidator.StandardNotation
top: field.top
bottom: field.bottom
}
font.pixelSize: field.pixelSize
placeholderText: "0.0"
anchors.leftMargin: 5
anchors.left: left_lbl.right
}
Label {
id: right_lbl
width: 44
height: field.cellHeight
text: field.right_text
anchors.verticalCenter: textField1.verticalCenter
horizontalAlignment: Text.AlignLeft
font.pixelSize: field.pixelSize
anchors.leftMargin: 5
anchors.margins: 10
verticalAlignment: Text.AlignVCenter
anchors.left: textField1.right
}
Label {
id: left_lbl
width: 57
height: field.cellHeight
text: field.left_text
anchors.top: top_lbl.bottom
anchors.topMargin: 0
anchors.left: top_lbl.left
anchors.leftMargin: 0
horizontalAlignment: Text.AlignRight
font.pixelSize: field.pixelSize
verticalAlignment: Text.AlignVCenter
}
}