当前位置: 首页 > news >正文

QML 自定义时间编辑控件

一.展示效果

qml自定义时间编辑控件

二.主界面调用

//main.qml
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Window 2.12
import "./qml"Window
{visible: truewidth: 400height: 300title: qsTr("Hello World")property date originDate: new Date()       //原始时间property var theme: QtObject {id: themeobjectName: "theme"property string fontFamily: 'Microsoft YaHei'property real fontSize: 14property int fontWeight: Font.Normalproperty color textColor: '#222222'property color borderColor: '#D3D3D3'property color sameMonthDateTextColor: "#444"property color selectedDateColor: Qt.platform.os === "osx" ? "#3778d0" : "#3778d0"property color selectedDateTextColor: "white"property color differentMonthDateTextColor: "#bbb"property color invalidDatecolor: "#dddddd"}Row{spacing: 10width: 120height: 35Text{color: "#ffffff"width: 40height:35antialiasing: truefont {family: theme.fontFamilypixelSize: theme.fontSizeweight: theme.fontWeight}text: qsTr('时间:')}CustomTimeEdit{id: timeEidtcolor: Qt.rgba(18/255,62/255,68/255,1)height: parent.height - 2width: 120selectionColor: theme.selectedDateColorhour: originDate.getHours()minute: originDate.getMinutes()}}
}

三.时间编辑控件封装

//CustomTimeEdit.qml
import QtQuick 2.11
import QtQuick.Controls 2.4Rectangle {id: timeEditproperty string timeproperty int hour: 0property int minute: 0property int timePointWidth: 24property int controlWidth: 60property color selectionColor: 'blue'property var theme: QtObject {id: themeobjectName: "theme"property string fontFamily: 'Microsoft YaHei'property real fontSize: 14property int fontWeight: Font.Normalproperty color textColor: '#222222'property color borderColor: '#D3D3D3'}border.width: 1border.color: theme.borderColorwidth: 160height: 26color: "#57b9a5"Row{id:timeTextspacing:1width: parent.width - control.widthheight: parent.heightTextInput {id: hoursheight: parent.heightcolor: "#ffffff"//enabled: falsewidth: timePointWidthfont {family: theme.fontFamilypixelSize: theme.fontSize - 1weight: theme.fontWeight}selectByMouse: truemaximumLength: 2selectionColor: timeEdit.selectionColormouseSelectionMode: TextInput.SelectWordsvalidator: IntValidator{bottom: 0; top: 23;}verticalAlignment: Text.AlignVCenterhorizontalAlignment: Text.AlignHCentertext: hour < 10 ? '0'+ hour: hour >= 24 ? 0 : houronEditingFinished:{hour = parseInt(hours.text.trim())}onActiveFocusChanged: {if (activeFocus){hours.selectAll();minutes.deselect();}}onTextChanged: {if (activeFocus){//hours.selectAll();//minutes.deselect();}}}Text {id: separatorwidth:6height: parent.heightcolor: "#ffffff"verticalAlignment: Text.AlignVCenterhorizontalAlignment: Text.AlignHCentertext: ":"}TextInput {id: minutesheight: parent.heightcolor: "#ffffff"width: timePointWidthfont {family: theme.fontFamilypixelSize: theme.fontSize - 1weight: theme.fontWeight}selectByMouse: truemaximumLength: 2//enabled: falseselectionColor: timeEdit.selectionColormouseSelectionMode: TextInput.SelectWordsvalidator: IntValidator{bottom: 0; top: 59;}verticalAlignment: Text.AlignVCenterhorizontalAlignment: Text.AlignHCentertext: minute < 10 ? '0'+ minute: minute >= 60 ? 0 : minuteonEditingFinished:{minute = parseInt(minutes.text.trim())}onActiveFocusChanged: {if (activeFocus){minutes.selectAll();hours.deselect();}}onTextChanged: {if (activeFocus){//minutes.selectAll();//hours.deselect();}}}}Rectangle{id: controlwidth: controlWidthanchors.right: parent.rightanchors.rightMargin: 1anchors.top: parent.topanchors.topMargin: 1anchors.bottom: parent.bottomanchors.bottomMargin: 1color: Qt.rgba(18/255,62/255,68/255,1)Canvas {id:timeIncanchors.right: parent.rightanchors.rightMargin: 0anchors.bottom: parent.bottomanchors.bottomMargin: 0anchors.top: parent.topanchors.topMargin: 0width: parent.heightheight:  parent.heightonPaint: {var ctx = getContext("2d")ctx.lineWidth = 1ctx.strokeStyle = Qt.rgba(100/255,1,1,1)ctx.beginPath()ctx.moveTo(width/4,height*5/8)ctx.lineTo(width/2,height*3/8)ctx.lineTo(width*3/4,height*5/8)//ctx.closePath()ctx.stroke()}MouseArea{anchors.fill: parentonClicked: {if (minutes.activeFocus){minute = parseInt(minutes.text.trim())minute = minute + 1;if(minute > 59){minute = 0}}else{hour = parseInt(hours.text.trim())hour = hour + 1;if(hour > 23){hour = 0;}if (!hours.activeFocus){hours.selectAll();}}}}}Canvas {anchors.right: timeInc.leftanchors.rightMargin: 0anchors.bottom: parent.bottomanchors.bottomMargin: 0anchors.top: parent.topanchors.topMargin: 0width: parent.heightheight:  parent.heightonPaint: {var ctx = getContext("2d")ctx.lineWidth = 1ctx.strokeStyle = Qt.rgba(100/255,1,1,1)ctx.beginPath()ctx.moveTo(width/4,height*3/8)ctx.lineTo(width/2,height*5/8)ctx.lineTo(width*3/4,height*3/8)//ctx.closePath()ctx.stroke()}MouseArea{anchors.fill: parentonClicked: {if (minutes.activeFocus){minute = parseInt(minutes.text.trim())minute = minute - 1;if(minute < 0){minute = 59}}else{hour = parseInt(hours.text.trim())hour = hour - 1;if(hour < 0){hour = 23;}if (!hours.activeFocus){hours.selectAll();}}}}}}
}

相关文章:

QML 自定义时间编辑控件

一.展示效果 qml自定义时间编辑控件 二.主界面调用 //main.qml import QtQuick 2.12 import QtQuick.Controls 2.5 import QtQuick.Window 2.12 import "./qml"Window {visible: truewidth: 400height: 300title: qsTr("Hello World")property date origi…...

后端程序员入门react笔记(八)-redux的使用和项目搭建

一个更好用的文档 添加链接描述 箭头函数的简化 //简化前 function countIncreAction(data) {return {type:"INCREMENT",data} } //简化后 const countIncreAction data>({type:"INCREMENT",data })react UI组件库相关资料 组件库连接和推荐 antd组…...

深度学习 精选笔记(13.2)深度卷积神经网络-AlexNet模型

学习参考&#xff1a; 动手学深度学习2.0Deep-Learning-with-TensorFlow-bookpytorchlightning ①如有冒犯、请联系侵删。 ②已写完的笔记文章会不定时一直修订修改(删、改、增)&#xff0c;以达到集多方教程的精华于一文的目的。 ③非常推荐上面&#xff08;学习参考&#x…...

【C#图解教程】笔记

文章目录 1. C#和.NET框架.NET框架的组成.NET框架的特点CLRCLICLI的重要组成部分各种缩写 2. C#编程概括标识符命名规则&#xff1a; 多重标记和值格式化数字字符串对齐说明符格式字段标准数字格式说明符标准数字格式说明符 表 3. 类型、存储和变量数据成员和函数成员预定义类型…...

A Workload‑Adaptive Streaming Partitioner for Distributed Graph Stores(2021)

用于分布式图存储的工作负载自适应流分区器 对象&#xff1a;动态流式大图 划分方式&#xff1a;混合割 方法&#xff1a;增量重划分 考虑了图查询算法&#xff0c;基于动态工作负载 考虑了双动态&#xff1a;工作负载动态&#xff1b;图拓扑结构动态 缺点&#xff1a;分配新顶…...

鸿蒙Harmony应用开发—ArkTS声明式开发(基础手势:Search)

搜索框组件&#xff0c;适用于浏览器的搜索内容输入框等应用场景。 说明&#xff1a; 该组件从API Version 8开始支持。后续版本如有新增内容&#xff0c;则采用上角标单独标记该内容的起始版本。 子组件 无 接口 Search(options?: { value?: string, placeholder?: Reso…...

GPIO八种工作模式实践总结

到目前为止我还是没搞懂&#xff0c;GPIO口输入输出模式下&#xff0c;PULLUP、PULLDOWN以及NOPULL之间的区别&#xff0c;从实践角度讲&#xff0c;也就是我亲自测试来看&#xff0c;能划分的区别有以下几点&#xff1a; GPIO_INPUT 在输入模式下使用HAL_GPIO_WritePin不能改变…...

ElementUI两个小坑

1.form表单绑定的是一个对象&#xff0c;表单里的一个输入项是对象的一个属性之一&#xff0c;修改输入项&#xff0c;表单没刷新的问题&#xff0c; <el-form :model"formData" :rules"rules" ref"editForm" class"demo-ruleForm"…...

前端基础——HTML傻瓜式入门(2)

该文章Github地址&#xff1a;https://github.com/AntonyCheng/html-notes 在此介绍一下作者开源的SpringBoot项目初始化模板&#xff08;Github仓库地址&#xff1a;https://github.com/AntonyCheng/spring-boot-init-template & CSDN文章地址&#xff1a;https://blog.c…...

操作系统(AndroidIOS)图像绘图的基本原理

屏幕显示图像的过程 我们知道&#xff0c;屏幕是由一个个物理显示单元组成&#xff0c;每一个单元我们可以称之为一个物理像素点&#xff0c;而每一个像素点可以发出多种颜色。 而图像&#xff0c;就是在不同的物理像素点上显示不同的颜色构成的。 像素点的颜色 像素的颜色是…...

测试用例的设计(2)

目录 1.前言 2.正交排列(正交表) 2.1什么是正交表 2.2正交表的例子 2.3正交表的两个重要性质 3.如何构造一个正交表 3.1下载工具 3.1构造前提 4.场景设计法 5.错误猜测法 1.前言 我们在前面的文章里讲了测试用例的几种设计方法,分别是等价类发,把测试例子划分成不同的类…...

HTML与CSS

前言 Java 程序员一提起前端知识&#xff0c;心情那是五味杂陈&#xff0c;百感交集。 说不学它吧&#xff0c;说不定进公司以后&#xff0c;就会被抓壮丁去时不时写点前端代码说学它吧&#xff0c;HTML、CSS、JavaScript 哪个不得下大功夫才能精通&#xff1f;学一点够不够用…...

App推广不再难!Xinstall神器助你快速获客,提升用户留存

在如今的移动互联网时代&#xff0c;App推广已经成为了各大应用商家争夺用户的重要手段。然而&#xff0c;面对竞争激烈的市场环境&#xff0c;如何快速提升推广效率&#xff0c;先人一步获得用户呢&#xff1f;这就需要我们借助专业的App全渠道统计服务商——Xinstall的力量。…...

MySQL建表以及excel内容导入

最近自学MySQL的使用&#xff0c;需要将整理好的excel数据导入数据库中&#xff0c;记录一下数据导入流程。 --建立数据库 create table SP_sjk ( --增加列 id NUMBER(20), mc VARCHAR2(300) ) /*表空间储存参数配置。一个数据库从逻辑上来说是由一个或多个表空间所组成&#…...

让el-input与其他组件能够显示在同一行

让el-input与其他组件能够显示在同一行 说明&#xff1a;由于el-input标签使用会默认占满一行&#xff0c;所以在某些需要多个展示一行的时候不适用&#xff0c;因此需要能够跟其他组件显示在同一行。 效果&#xff1a; 1、el-input标签内使用css属性inline 111<el-inp…...

学完Efficient c++ (44-45)

条款 44&#xff1a;将与参数无关的代码抽离模板 模板可以节省时间和避免代码重复&#xff0c;编译器会为填入的每个不同模板参数具现化出一份对应的代码&#xff0c;但长此以外&#xff0c;可能会造成代码膨胀&#xff08;code bloat&#xff09;&#xff0c;生成浮夸的二进制…...

鸿蒙Harmony应用开发—ArkTS声明式开发(容器组件:ColumnSplit)

将子组件纵向布局&#xff0c;并在每个子组件之间插入一根横向的分割线。 说明&#xff1a; 该组件从API Version 7开始支持。后续版本如有新增内容&#xff0c;则采用上角标单独标记该内容的起始版本。 子组件 可以包含子组件。 ColumnSplit通过分割线限制子组件的高度。初始…...

jenkins部署go应用 基于docker-compose

丢弃旧的的构建 github 拉取代码 指定go的编译版本 安装插件 拉取代码是排除指定的配置文件 比如 conf/config.yaml 文件 填写配置文件内容 比如测试环境一些主机信息 等 可以配置里面 构建的时候选择此文件替换开发提交的配置文件。。。。 编写docker-compose 文件 docker…...

【晴问算法】入门篇—贪心算法—整数配对

题目描述 有两个正整数集合S、T&#xff0c;其中S中有n个正整数&#xff0c;T中有m个正整数。定义一次配对操作为&#xff1a;从两个集合中各取出一个数a和b&#xff0c;满足a∈S、b∈T、a≤b&#xff0c;配对的数不能再放回集合。问最多可以进行多少次这样的配对操作。 输入描…...

九种背包问题(C++)

0-1背包&#xff0c;背包大小target&#xff0c;占用容积vec[i][0]&#xff0c;可以带来的利益是vec[i][1] 一件物品只能取一次,先遍历物品然后遍历背包更新不同容积下最大的利益 int func(vector<vector<int>>&vec,int target){vector<int>dp(target1,…...

conda相比python好处

Conda 作为 Python 的环境和包管理工具&#xff0c;相比原生 Python 生态&#xff08;如 pip 虚拟环境&#xff09;有许多独特优势&#xff0c;尤其在多项目管理、依赖处理和跨平台兼容性等方面表现更优。以下是 Conda 的核心好处&#xff1a; 一、一站式环境管理&#xff1a…...

【快手拥抱开源】通过快手团队开源的 KwaiCoder-AutoThink-preview 解锁大语言模型的潜力

引言&#xff1a; 在人工智能快速发展的浪潮中&#xff0c;快手Kwaipilot团队推出的 KwaiCoder-AutoThink-preview 具有里程碑意义——这是首个公开的AutoThink大语言模型&#xff08;LLM&#xff09;。该模型代表着该领域的重大突破&#xff0c;通过独特方式融合思考与非思考…...

Mac软件卸载指南,简单易懂!

刚和Adobe分手&#xff0c;它却总在Library里给你写"回忆录"&#xff1f;卸载的Final Cut Pro像电子幽灵般阴魂不散&#xff1f;总是会有残留文件&#xff0c;别慌&#xff01;这份Mac软件卸载指南&#xff0c;将用最硬核的方式教你"数字分手术"&#xff0…...

vue3 定时器-定义全局方法 vue+ts

1.创建ts文件 路径&#xff1a;src/utils/timer.ts 完整代码&#xff1a; import { onUnmounted } from vuetype TimerCallback (...args: any[]) > voidexport function useGlobalTimer() {const timers: Map<number, NodeJS.Timeout> new Map()// 创建定时器con…...

unix/linux,sudo,其发展历程详细时间线、由来、历史背景

sudo 的诞生和演化,本身就是一部 Unix/Linux 系统管理哲学变迁的微缩史。来,让我们拨开时间的迷雾,一同探寻 sudo 那波澜壮阔(也颇为实用主义)的发展历程。 历史背景:su的时代与困境 ( 20 世纪 70 年代 - 80 年代初) 在 sudo 出现之前,Unix 系统管理员和需要特权操作的…...

LLM基础1_语言模型如何处理文本

基于GitHub项目&#xff1a;https://github.com/datawhalechina/llms-from-scratch-cn 工具介绍 tiktoken&#xff1a;OpenAI开发的专业"分词器" torch&#xff1a;Facebook开发的强力计算引擎&#xff0c;相当于超级计算器 理解词嵌入&#xff1a;给词语画"…...

OpenLayers 分屏对比(地图联动)

注&#xff1a;当前使用的是 ol 5.3.0 版本&#xff0c;天地图使用的key请到天地图官网申请&#xff0c;并替换为自己的key 地图分屏对比在WebGIS开发中是很常见的功能&#xff0c;和卷帘图层不一样的是&#xff0c;分屏对比是在各个地图中添加相同或者不同的图层进行对比查看。…...

图表类系列各种样式PPT模版分享

图标图表系列PPT模版&#xff0c;柱状图PPT模版&#xff0c;线状图PPT模版&#xff0c;折线图PPT模版&#xff0c;饼状图PPT模版&#xff0c;雷达图PPT模版&#xff0c;树状图PPT模版 图表类系列各种样式PPT模版分享&#xff1a;图表系列PPT模板https://pan.quark.cn/s/20d40aa…...

Git 3天2K星标:Datawhale 的 Happy-LLM 项目介绍(附教程)

引言 在人工智能飞速发展的今天&#xff0c;大语言模型&#xff08;Large Language Models, LLMs&#xff09;已成为技术领域的焦点。从智能写作到代码生成&#xff0c;LLM 的应用场景不断扩展&#xff0c;深刻改变了我们的工作和生活方式。然而&#xff0c;理解这些模型的内部…...

uniapp 字符包含的相关方法

在uniapp中&#xff0c;如果你想检查一个字符串是否包含另一个子字符串&#xff0c;你可以使用JavaScript中的includes()方法或者indexOf()方法。这两种方法都可以达到目的&#xff0c;但它们在处理方式和返回值上有所不同。 使用includes()方法 includes()方法用于判断一个字…...