Ed *_*Nio 5 qt qml qspinbox qtquickcontrols2
我需要使用 double ,spinbox在QML view这种情况下,我基于spinbox此示例 。
SpinBox {
id: spinbox
from: 0
value: 110
to: 100 * 100
stepSize: 100
anchors.centerIn: parent
property int decimals: 2
property real realValue: value / 100
validator: DoubleValidator {
bottom: Math.min(spinbox.from, spinbox.to)
top: Math.max(spinbox.from, spinbox.to)
}
textFromValue: function(value, locale) {
return Number(value / 100).toLocaleString(locale, 'f', spinbox.decimals)
}
valueFromText: function(text, locale) {
return Number.fromLocaleString(locale, text) * 100
}
}
Run Code Online (Sandbox Code Playgroud)
似乎当您使用自定义旋转框时,它不会显示为“经典”旋转框。显示如下:
但是,按钮对于我的界面来说太大了。我想知道是否有一种简单的方法可以将旋转框显示为“经典”旋转框,如下所示:
QtQuick.Controls 1.x如果您对在项目中使用旧版本没有保留...
您可以通过使用前缀在同一个文件中使用QtQuick.Controls 1.x和QtQuick.Controls 2.0。
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Controls 1.4 as OldCtrl
ApplicationWindow { // Unprefixed, therefor from the new QtQuick.Controls 2.0
id: root
visible: true
width: 400; height: 450
OldCtrl.SpinBox {
width: 100
value: 20
decimals: 2
}
}
Run Code Online (Sandbox Code Playgroud)
这是这方面的文档SpinBox
如果您想使用QtQuick.Controls 2.x,那么您可以为up.indicator和定义自定义项目down.indicator
SpinBox {
id: sb
value: 20
up.indicator: Rectangle {
height: parent.height / 2
anchors.right: parent.right
anchors.top: parent.top
implicitHeight: 40
implicitWidth: 40 // Adjust width here
color: sb.up.pressed ? "#e4e4e4" : "#f6f6f6"
border.color: enabled ? "#21be2b" : "#bdbebf"
Text {
text: '+'
anchors.centerIn: parent
}
}
down.indicator: Rectangle {
height: parent.height / 2
anchors.right: parent.right
anchors.bottom: parent.bottom
implicitHeight: 40
implicitWidth: 40 // Adjust width here
color: sb.down.pressed ? "#e4e4e4" : "#f6f6f6"
border.color: enabled ? "#21be2b" : "#bdbebf"
Text {
text: '-'
anchors.centerIn: parent
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3428 次 |
| 最近记录: |