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

qml可拖动折线图

qt5.15.2  qml

演示:

可直接运行的代码demo:

import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 import QtQuick.Shapes 1.15 ApplicationWindow { id: rootWindow visible: true width: 1200 height: 800 title: "可拖动折线图编辑器 - 长按拖动模式" color: "#1a1a1a" // 图表数据点(x: 0-100, y: 0-100) property var dataPoints: [ {x: 0, y: 20}, {x: 10, y: 45}, {x: 20, y: 30}, {x: 30, y: 60}, {x: 40, y: 35}, {x: 50, y: 80}, {x: 60, y: 55}, {x: 70, y: 90}, {x: 80, y: 40}, {x: 90, y: 65}, {x: 100, y: 50} ] // 图表配置 property int chartMargin: 80 property int pointRadius: 10 property int lineWidth: 3 property color lineColor: "#00a8e8" property color pointColor: "#ffffff" property color pointHoverColor: "#00a8e8" property color gridColor: "#333333" property color textColor: "#888888" // 当前选中的点索引 property int selectedPointIndex: -1 property int hoveredPointIndex: -1 // 拖动状态 property bool isDragging: false property int draggedPointIndex: -1 property real dragOffsetX: 0 property real dragOffsetY: 0 ColumnLayout { anchors.fill: parent spacing: 0 // 顶部工具栏 Rectangle { Layout.fillWidth: true height: 60 color: "#252525" Row { anchors.centerIn: parent spacing: 20 Button { text: "重置示例" onClicked: { dataPoints = [ {x: 0, y: 20}, {x: 10, y: 45}, {x: 20, y: 30}, {x: 30, y: 60}, {x: 40, y: 35}, {x: 50, y: 80}, {x: 60, y: 55}, {x: 70, y: 90}, {x: 80, y: 40}, {x: 90, y: 65}, {x: 100, y: 50} ] selectedPointIndex = -1 canvas.requestPaint() } } Button { text: "添加点" onClicked: { if (dataPoints.length < 20) { var lastX = dataPoints[dataPoints.length - 1].x var newX = Math.min(100, lastX + 10) dataPoints.push({x: newX, y: 50}) canvas.requestPaint() } } } Button { text: "删除选中" onClicked: { if (selectedPointIndex >= 0 && dataPoints.length > 2) { dataPoints.splice(selectedPointIndex, 1) selectedPointIndex = -1 canvas.requestPaint() } } } Rectangle { width: 1 height: 30 color: "#444444" anchors.verticalCenter: parent.verticalCenter } Text { text: isDragging ? "拖动中... 松开固定位置" : (selectedPointIndex >= 0 ? "选中点 #" + (selectedPointIndex + 1) + " X: " + dataPoints[selectedPointIndex].x.toFixed(1) + " Y: " + dataPoints[selectedPointIndex].y.toFixed(1) : "长按拐点拖动,松手固定位置") co
http://www.jsqmd.com/news/412555/

相关文章:

  • 【linuxqt】qsql_mysql.cpp:57:10: fatal error: QtSql/private/qsqldriver_p.h: No such file or directory
  • 我草我怎么这么牛
  • 基于 AWS Global Accelerator 实现全球低延迟访问-RapidX 全球加速方案
  • day96(2.25)——leetcode面试经典150
  • 【Linux】进程的页表详解
  • YOLO26最新创新改进系列:主干网络全新设计——EfficientNetV2-BackBone ,引入渐进式学习策略、自适应正则强度调整机制,共同优化训练速度和参数效率,全方位提升模型检测性能!!
  • YOLO26最新创新改进系列:融入AKConv(可改变核卷积),加强特征提取,任意数量的参数和任意采样形状,为网络开销和性能之间的权衡提供了更丰富的选择。 拉升检测性能!
  • 瑞芯微开发板开机自启动设置
  • FastAsyncWorldEdit zh-cn strings.json 中文汉化
  • **0-1 背包问题中回溯法的搜索过程、通用解题步骤及两种算法实现框架(递归与非递归)**,是算法设计与分析中的经典范例
  • SRE 团队体系建设之路
  • 惊叹!大数据数据增强如何颠覆传统模式
  • int[] 与 integer[] 相互转换
  • Amazon EMR 高可用 EMR 部署注意事项及关键配置
  • SolidPlant 2020管道设计软件安装包(含详细图文教程)|兼容SolidWorks 2017及以上版本
  • 【踩坑】MacOS26上的浏览器无法显示麦克风/摄像头列表
  • 【DFS】BISHI77数水坑
  • SimpleDateFormat(YYYY-MM-dd)格式化时间出现了bug?
  • 《P1973 [NOI2011] NOI 嘉年华》
  • 华为OD机考双机位C卷 - 几何平均值最大子数组 (Java Python JS GO C++ C)
  • 实现一个简单的文本摘要生成器。
  • pyTorch环境搭建及遇到的算力问题
  • 卷积神经网络(CNN)简介-卷积神经网络介绍
  • 【RCCL】RCCL工具
  • 大数据交易数据湖架构设计指南
  • 2026年2月25日
  • 什么是动态住宅 IP 代理?动态 IP 最常用在哪些业务
  • 搜索已死,问答永生:2026年6大特色GEO服务商实战图谱与避坑指南 - 品牌2025
  • LLM支持的AI Agent上下文感知推荐技术
  • langchain架构设计以及应用案例分享