默认情况下,SpinBox中文本的文本对齐方式是居中。SpinBox documentation声明有一个horizontalAlignment属性,但是当我尝试指定水平对齐时,我得到了以下错误:
Invalid property name "horizontalAlignment". (M16)
我的完整SpinBox代码如下:
SpinBox {
editable: true
horizontalAlignment: Qt.AlignLeft
from: 1
to: 10000
value: model.numberOfElements
}如何在Qt Controls 2.0中对齐SpinBox中的文本?
发布于 2019-01-24 00:56:37
首先,您指出的文档链接来自Qt Quick Controls 1的SpinBox,Qt Quick Controls 2的链接是:https://doc.qt.io/qt-5/qml-qtquick-controls2-spinbox.html。
考虑到上面的Qt Quick Controls,2有一个文档指出了如何定制控件:Customizing Qt Quick Controls 2。
在SpinBox的情况下,解决方案是:
import QtQuick.Controls 2.5
SpinBox {
id: control
value: 50
editable: true
contentItem: TextInput {
z: 2
text: control.textFromValue(control.value, control.locale)
font: control.font
color: "#21be2b"
selectionColor: "#21be2b"
selectedTextColor: "#ffffff"
horizontalAlignment: Qt.AlignLeft
verticalAlignment: Qt.AlignVCenter
readOnly: !control.editable
validator: control.validator
inputMethodHints: Qt.ImhFormattedNumbersOnly
}
}https://stackoverflow.com/questions/54331909
复制相似问题