Some layout fixes to toggle and slider
NSlider(withLabel): fix some small layout issues NToggle: fix vertical centering of the thumb
This commit is contained in:
parent
bb7f957e44
commit
11f6475b9f
3 changed files with 66 additions and 14 deletions
61
Widgets/NSliderWithLabel.qml
Normal file
61
Widgets/NSliderWithLabel.qml
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import qs.Commons
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
|
||||
RowLayout {
|
||||
id: root
|
||||
|
||||
// Properties that mirror NSlider
|
||||
property real from: 0
|
||||
property real to: 1
|
||||
property real value: 0
|
||||
property real stepSize: 0.01
|
||||
property var cutoutColor
|
||||
property bool snapAlways: true
|
||||
property real heightRatio: 0.75
|
||||
property bool showPercentage: true
|
||||
property string suffix: "%"
|
||||
property int decimalPlaces: 0 // 0 for integers, 1 for one decimal place, etc.
|
||||
|
||||
// Signals
|
||||
signal moved(real value)
|
||||
signal pressedChanged(bool pressed)
|
||||
|
||||
spacing: Style.marginS * scaling
|
||||
|
||||
NSlider {
|
||||
id: slider
|
||||
Layout.fillWidth: true
|
||||
from: root.from
|
||||
to: root.to
|
||||
value: root.value
|
||||
stepSize: root.stepSize
|
||||
cutoutColor: root.cutoutColor
|
||||
snapAlways: root.snapAlways
|
||||
heightRatio: root.heightRatio
|
||||
stableWidth: true
|
||||
minWidth: 200 * scaling
|
||||
|
||||
onMoved: root.moved(value)
|
||||
onPressedChanged: root.pressedChanged(pressed)
|
||||
}
|
||||
|
||||
NText {
|
||||
id: percentageLabel
|
||||
visible: root.showPercentage
|
||||
text: {
|
||||
if (root.decimalPlaces === 0) {
|
||||
return Math.round(slider.value * 100) + root.suffix
|
||||
} else {
|
||||
return (slider.value * 100).toFixed(root.decimalPlaces) + root.suffix
|
||||
}
|
||||
}
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
Layout.leftMargin: Style.marginS * scaling
|
||||
Layout.preferredWidth: 50 * scaling
|
||||
horizontalAlignment: Text.AlignRight
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue