QML学习
- Slider例程
- 视频讲解
- 代码
main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15Window {width: 640height: 480visible: truetitle: qsTr("Hello World")Slider {id: sliderfrom: 0to: 100value: 50handle: Rectangle {implicitWidth: 30implicitHeight: 30border.width: 1x: slider.leftPadding+ slider.visualPosition* (slider.availableWidth - width)y: slider.height / 2 - height / 2Text {anchors.centerIn: parentfont.pointSize: 15text: slider.value.toFixed(0)}}background: Rectangle {implicitWidth: 200implicitHeight: 40border.width: 1Rectangle {width: parent.width - slider.leftPadding- slider.rightPaddingheight: 10radius: 5anchors.centerIn: parentcolor: "black"}Rectangle {x: slider.leftPaddingwidth: slider.visualPosition * parent.width- x - slider.rightPaddingheight: 10radius: 5anchors.verticalCenter: parent.verticalCentercolor: "red"}}}
}
演示
视频讲解