QML 自定义Slider
来源:互联网 发布:高德软件股票行情 编辑:程序博客网 时间:2024/04/30 11:58
QML 自定义Slider
此博客始创于:http://blog.csdn.net/lys211
转载请注明出处
写这个时参考了众多代码,现在把qml 里slider的样式修改的代码贴到这里备份。
效果图:
代码贴这里一份:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.2
import QtGraphicalEffects 1.0
import QtQml 2.2
Rectangle {
width: 500
height: 500//color: "#25b1e8"
Slider {
id: sliderHorizontal1
x: 21
y: 33
width: 458
height: 22
value:0.1
tickmarksEnabled: true
}
Slider {
id: sliderHorizontal2
x: 21
y: 87
width: 458
height: 22
value:0.3
tickmarksEnabled: true
//stepSize: 0.1;
style:SliderStyle{
groove:Rectangle{
implicitHeight: 8;
implicitWidth: sliderHorizontal2.width;
color: "#25b1e8";
radius: 8;
}
handle: Rectangle{
anchors.centerIn: parent;
color: control.pressed ? "green":"#25b1e8";
radius: 6;
width: 24;
height: 24;
}
}
}
Slider {
id: sliderHorizontal3
x: 21
y: 144
width: 458
height: 22;
style:SliderStyle{
groove:Rectangle{
implicitHeight: 8;
implicitWidth: sliderHorizontal2.width;
color: "#25b1e8";
radius: 8;
}
handle: Rectangle{
anchors.centerIn: parent;
color: control.pressed ? "lightblue":"#25b1e8";
radius: 12;
width: 24;
height: 24;
Text {
anchors.centerIn: parent;
text: String(control.value).slice(0,4);//Math.round(control.value)*100 + "%";
color: "blue";
}
}
}
}
Slider {
id: sliderHorizontal4;
x: 21
y: 207
width: 458
height: 22;
value:0.3;
style:SliderStyle{
//padding.left:-150;
groove:Rectangle{
//anchors.centerIn: parent;
implicitHeight: 2;
implicitWidth: sliderHorizontal4.width;
color: "white";
radius: 1;
}
handle: Rectangle{
anchors.centerIn: parent;
color: control.pressed ? "lightblue":"blue";
radius: 2;
width: 12;
height: 30;
MouseArea{
anchors.fill: parent;
onPressed: {
console.log("handle MouseArea:", mouse.x, mouse.y, x, mouseX, mouseY);
}
}
onXChanged: {
console.log("handle onXChanged:", x);
}
}
panel:Rectangle{
id:panel4
anchors.fill: parent;
color: "#25b1e8";
Loader{
id:grooveLoader4;
anchors.centerIn: parent;
sourceComponent: groove;
}
Loader{
id:handleLoader4;
anchors.verticalCenter: grooveLoader4.verticalCenter;
x:Math.min(grooveLoader4.x + (control.value * grooveLoader4.width)/(control.maximumValue - control.minimumValue) - item.width/2
, grooveLoader4.width);
sourceComponent: handle;
Component.onCompleted: {
console.log("panel", control.maximumValue, control.minimumValue, item.width, x)
}
onXChanged: {
console.log("panel handleLoader4 onXChanged:", x);
}
}
Text {
anchors.bottom: handleLoader4.top;
anchors.horizontalCenter: handleLoader4.horizontalCenter;
text: String(control.value).slice(0,4);//Math.round(control.value)*100 + "%";
color: "blue";
}
}
}
}
Slider {
id: sliderHorizontal5;
x: 21
y: 267
width: 458
height: 22;
value:0.3;
style:SliderStyle{
//padding.left:-150;
groove:Rectangle{
//anchors.centerIn: parent;
implicitHeight: 2;
implicitWidth: sliderHorizontal5.width;
color: "white";
radius: 1;
}
handle: Rectangle{
anchors.centerIn: parent;
color: control.pressed ? "lightblue":"blue";
radius: 4;
width: 12;
height: 30;
MouseArea{
anchors.fill: parent;
onPressed: {
console.log("handle MouseArea:", mouse.x, mouse.y, x, mouseX, mouseY);
}
}
onXChanged: {
console.log("handle onXChanged:", x);
}
Rectangle{
anchors.centerIn: parent;
height: parent.height - parent.width;
width: 1;
color: "white";
}
}
panel:Rectangle{
id:panel5
anchors.fill: parent;
color: "#25b1e8";
LinearGradient{
anchors.fill: panel5;
gradient: Gradient{
GradientStop { position: 0.00; color: "lightblue";}
GradientStop { position: 1.00; color: "blue";}
}
start: Qt.point(0, 0);
end:Qt.point(panel5.width, 0);
}
Loader{
id:grooveLoader5;
anchors.centerIn: parent;
sourceComponent: groove;
}
Loader{
id:handleLoader5;
anchors.verticalCenter: grooveLoader5.verticalCenter;
x:Math.min(grooveLoader5.x + (control.value * grooveLoader5.width)/(control.maximumValue - control.minimumValue) - item.width/2
, grooveLoader5.width);
sourceComponent: handle;
Component.onCompleted: {
console.log("panel", control.maximumValue, control.minimumValue, item.width, x)
}
onXChanged: {
console.log("panel handleLoader4 onXChanged:", x);
}
}
Text {
anchors.bottom: handleLoader5.top;
anchors.horizontalCenter: handleLoader5.horizontalCenter;
text: String(control.value).slice(0,4);//Math.round(control.value)*100 + "%";
color: "blue";
}
}
}
}
}
也提供整个文件的下载链接:
http://download.csdn.net/detail/lys211/8541163
0 0
- QML 自定义Slider
- 自定义qml滑动条Slider
- 自定义 slider
- 自定义slider
- 自定义slider
- qml学习-------------Slider(滑块)
- Qt-QML-Slider-滑块-Style
- Qt-QML-Slider-滑块-Style-后继
- iOS---------自定义slider
- SWT自定义组件之Slider
- IOS 控件 自定义UISlider Slider
- 如何得到QML中的TextArea的slider的位置信息
- QML学习之基本元素ProgressBar, TabView, Slider介绍
- QML之自定义Button
- 自定义QML模块
- QML 自定义进度条样式
- qml自定义标题栏
- QML自定义鼠标样式
- tomcat msm部署
- Android Metro风格的Launcher开发系列第二篇
- C++的五大内存分区
- 深入解读Tomcat(二)
- ecache页面缓存问题及处理
- QML 自定义Slider
- 51单片机的data、idata、pdata、xdata的区别
- 深入解读Tomcat(三)
- C#操作sql通用类 SQLHelper
- Apache服务器的启动以及 403 forbidden 问题的解决
- java 容器深入研究之使用Abstract类定制
- 查找maven中的groupId,artifactId,version等信息的方式
- Servlet 3.0 新特性详解(五)ServletContext 的性能增强及HttpServletRequest 对文件上传的支持
- 04 多线程