Qt-QML-Slider-滑块-Style-后继

简介: 首先了,先把我上篇文章的demo准备好,不过我上次写的被我删除了,这次就重新写了一个,上代码

import QtQuick 2.5

import QtQuick.Controls 1.4

import QtQuick.Controls.Styles 1.4

ApplicationWindow {

   visible: true

   width: 1366

   height: 768

   title: qsTr("DLSlider")

   Slider

   {

       width: 600

       height: 20

       x: (parent.width - width)/2

       y: (parent.height - height)/2

       value: 0.1

       stepSize: 0.01

       onValueChanged:

       {

           console.log(value)

       }


       style: SliderStyle

       {

           handle: Rectangle


           {

               anchors.centerIn: parent;

               color:control.pressed ? "white":"lightgray";

               border.color: "gray";

               border.width: 2;

               width: 34;

               height: 34;

               radius: 12;

               Text{


                   anchors.centerIn: parent;

                   text: control.value;

                   color: "red";

               }


           }

           groove:Rectangle

           {

               implicitHeight:8

               color:"gray"

               radius:8

           }

       }


   }




}




详细解释大家可以看上一篇博客

image.png

这是目前的样式,和上一篇中基本一样,但是不是我要的样式

这里将说下升级版

 image.png

这样的效果是我想要的效果,上面是进度条,下面是可以拖动的指针,不过呢,能力有限,没有通过编写style实现成功,我用了一个投机取巧的办法来实现。

 

下面先上我最后的效果截图image.png

上源代码



import QtQuick 2.5

import QtQuick.Controls 1.4

import QtQuick.Controls.Styles 1.4

ApplicationWindow {

   visible: true

   width: 1366

   height: 768

   title: qsTr("DLSlider")


   Rectangle

   {

       id:line_parent

       width: 800

       height: 20

       x: (parent.width - width)/2

       y: (parent.height - height)/2

       color: "#1ae5ec"

       Rectangle

       {

           id:line_child

           height: line_parent.height

           anchors.top:parent.top

           anchors.left: parent.left

           width: parent.width*m_Slider.value

           color: "red"


       }

   }


   Slider

   {

       id:m_Slider

       anchors.top: line_parent.top

       anchors.left: line_parent.left

       anchors.leftMargin: -5.5

       height: line_parent.height*2

       width: line_parent.width+11

       value: 0.1

       stepSize: 0.01

       onValueChanged:

       {

           console.log(value)

       }


       style: SliderStyle

       {

           handle: Rectangle

           {

               anchors.horizontalCenter:parent.horizontalCenter

               anchors.bottom:parent.bottom

               width:11

               height:16

               color:"transparent"

               Image {

                   width: 11

                   height: 16

                   anchors.horizontalCenter: parent.horizontalCenter

                   anchors.bottom: parent.bottom

                   anchors.bottomMargin: -8

                   source: "qrc:/Images/ppointer.png"

               }



           }

           groove:Rectangle

           {

               color:"transparent"

           }

       }


   }




}






剩下的需要大家自行对比了,困了,要睡觉了


目录
相关文章
|
16天前
Qt Style And Style Sheet
Qt Style And Style Sheet
22 1
|
4月前
|
C++ UED
C++ Qt开发:Slider滑块条组件
Qt 是一个跨平台C++图形界面开发库,利用Qt可以快速开发跨平台窗体应用程序,在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置,实现图形化开发极大的方便了开发效率,本章将重点介绍`Slider`滑块条组件的常用方法及灵活运用。当涉及到C++ Qt开发中的`Slider`滑块条组件时,你可能会用到`QSlider`类。`QSlider`是一个用于选择整数值的控件,常用于调整范围内的数值,如音量、亮度等。在水平方向上的`Slider`通常被称为水平滑块(Horizontal Slider),而在垂直方向上的Slider被称为垂直滑块(Vertical Slider)。
94 0
|
XML 编解码 JSON
Qt-QML-C++交互实现文件IO系统-后继-读取XML文件和创建XML文件
在前面两篇中,大致完成了一个文件IO的读和写操作。前面两篇文章链接
309 0
Qt-QML-C++交互实现文件IO系统-后继-读取XML文件和创建XML文件
|
XML JSON 移动开发
Qt-QML-C++交互实现文件IO系统-后继-具体文件IO的实现
在上一篇文章中,我大致将这个QML中的文件IO类搭出了大致的框架,那么,今天抽时间写了一点文件的读写,这里我使用的文件流来读写文件。
128 0
Qt-QML-C++交互实现文件IO系统-后继-具体文件IO的实现
|
自然语言处理
Qt-QML-Slider-滑块-Style
感觉滑块这个东西,可以算是一个基本模块了,在我的项目中也有这个模块,今天我将学一下一下滑块的使用以及美化工作。
367 0
Qt-QML-Slider-滑块-Style
Qt-QML-Charts-ChartView-编译错误-ASSERT: “!“No style available without QApplication!
昨天本来是回家想好好琢磨一下使用Chart来绘制曲线的,奈何在建立项目的时候也就卡住了,加上心情比较烦躁,也没有耐心寻找答案就草草了事。所以今天继续搞定这个。
336 0
Qt-QML-Charts-ChartView-编译错误-ASSERT: “!“No style available without QApplication!
Qt编写自定义控件28-颜色滑块面板
一、前言 相比于上一个颜色按钮面板,此控件就要难很多,颜色值有三种表示形式,除了程序员最常用的RGB以外,还有HSB和CMY方式。RGB色彩模式是工业界的一种颜色标准,是通过对红(R)、绿(G)、蓝(B)三个颜色通道的变化以及它们相互之间的叠加来得到各式各样的颜色的,RGB即是代表红、绿、蓝三个通道的颜色,这个标准几乎包括了人类视力所能感知的所有颜色,是目前运用最广的颜色系统之一。
926 0