linux上QtChart的触屏缩放和移动
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
linux上QtChart的触屏缩放和移动
linux多点触摸配置:
export
QWS_MOUSE_PROTO=evdevtouch:/dev/input/event15 export QT_QPA_EDEV_MOUSE_PARAMETERS=abs 注意:编译Qt时需配置以支持多点触控
如下:实现曲线的单指移动,双手缩放,双击恢复
ChartView {
id:chartView
title: "Series Demo"
anchors.fill: parent
legend.visible: false
antialiasing: true
property double seY
property double m_A
property double m_B
property double m_a
property double m_b
property double t
property double intv
property double cnt
property double distanceX :0.0
property double distanceY :0.0
property double scaleOffset: 1
property double scrollLeftValue: 0
property double scrollUpValue: 0
property int touchStartTime: 0
property int touchEndTime: 0
property int times: 0
function getCurrentTime()
{
var time = new Date();
var ms = time.getSeconds() * 1000 + time.getMilliseconds(); return ms;
}
ValueAxis {
id: axisX
min: 0
max: 1000
tickCount: 13
titleText: "t"
labelFormat: "%d"
titleFont.pixelSize: controls.isHigh?20:12
labelsFont.pixelSize: controls.isHigh?20:12
}
ValueAxis {
id: axisY
min: -0.5
max: 1.5
tickCount:9
titleText: "℃"
labelFormat: "%d"
titleFont.pixelSize: controls.isHigh?20:12
labelsFont.pixelSize: controls.isHigh?20:12
}
LineSeries {
id: series1
axisX: axisX
axisY: axisY
useOpenGL: true
name: qsTr("示例曲线")
}
ScatterSeries {
id: series2
axisX: axisX
axisY: axisY
}
MultiPointTouchArea{
anchors.fill: parent
// mouseEnabled: false
touchPoints: [
TouchPoint{id:point1},
TouchPoint{id:point2}
]
onPressed: {
chartView.times += 1
if(chartView.times == 1)
{
chartView.touchStartTime = chartView.getCurrentTime();
}
}
onGestureStarted: {
chartView.times = 0;
if(point2.previousX == point2.x && point2.previousY== point2.y)//单指触摸,移动
{
chartView.distanceX = point1.x - point1.previousX;
chartView.distanceY = point1.y - point1.previousY
chartView.scrollLeft(chartView.distanceX)
chartView.scrollUp(chartView.distanceY)
chartView.scrollLeftValue = chartView.distanceX + chartView.scrollLeftValue ;
chartView.scrollUpValue =chartView.distanceY + chartView.scrollUpValue;
}
else
{
var disPreY = Math.abs(point2.previousY- point1.previousY) var disY = Math.abs(point2.y - point1.y)
var temp =disY - disPreY
if(temp > 0)
{
if(chartView.scaleOffset < 1)
chartView.scaleOffset = 1;
chartView.scaleOffset += temp/5000 ;
}
else
{
if(chartView.scaleOffset > 1)
chartView.scaleOffset = 1;
chartView.scaleOffset += temp/5000;
}
chartView.zoom(chartView.scaleOffset )
}
}
onReleased: {
if(chartView.times == 2)
{
chartView.touchEndTime = chartView.getCurrentTime();
if(chartView.touchEndTime - chartView.touchStartTime < 300)//计算两次点击的实际间隔,小于300ms则认为是双击{
chartView.zoomReset()
axisX.min = 0
axisX.max = chartView.t
axisY.min = -Math.ceil(Math.abs(chartView.m_A)+Math.abs(chartView.m_B));
axisY.max = Math.ceil(Math.abs(chartView.m_A)+Math.abs(chartView.m_B));
}
chartView.times = 0;
}
}
}
}
Component.onCompleted: {
chartView.t = 0;
chartView.intv=0.01;
/doc/2914132562.html,t = 2000;
chartView.m_A=3;
chartView.m_B=4;
chartView.m_a=5;
chartView.m_b=6;
axisY.min = -Math.ceil(Math.abs(chartView.m_A)+Math.abs(chartView.m_B));
axisY.max = Math.ceil(Math.abs(chartView.m_A)+Math.abs(chartView.m_B));
axisX.min = 0
for (var i = 0; i <=
/doc/2914132562.html,t; i++) { chartView.seY =chartView. m_A * Math.sin(2*3.14*chartView.m_a * chartView.t) + chartView.m_B * Math.sin(2*3.14*chartView.m_b * chartView.t)
series1.append(chartView.t, chartView.seY);
// series2.append(chartView.t, chartView.seY);
chartView.t+=chartView.intv;
}
axisX.max = chartView.t
}。