Qt实现触摸屏校准界面

更新时间:2023-07-27 18:26:10 阅读: 评论:0

Qt实现触摸屏校准界⾯Qt4.8.6 arm 平台
根据qt-everywhere-opensource-src-4.8.6/examples/qws/moucalibration ⽰例修改
calibration.h
#ifndef CALIBRATION_H
#define CALIBRATION_H
#include <QDialog>
#include <QWSPointerCalibrationData>
//! [0]酒龙诗虎
class Calibration : public QDialog
{
public:
Calibration();
~Calibration();
int exec();
protected:
void paintEvent(QPaintEvent*);
void mouReleaEvent(QMouEvent*);
void accept();
private:
QWSPointerCalibrationData data;
int pressCount;
};
/
/! [0]
#endif
calibration.cpp
#include "calibration.h"
#include <QDebug>
#include <QLabel>
#include <QWSPointerCalibrationData>
#include <QPainter>
#include <QFile>
#include <QTimer>
#include <QApplication>
#include <QDesktopWidget>
#include <QMouEvent>
#include <QScreen>
低碳技术
#include <QWSServer>
Calibration::Calibration()
{
QRect desktop = QApplication::desktop()->geometry();
古丈毛尖tGeometry(desktop);
tFocusPolicy(Qt::StrongFocus);
tFocus();
tModal(true);
int width = qt_screen->deviceWidth();
int width = qt_screen->deviceWidth();
int height = qt_screen->deviceHeight();
int dlx = width/2;
int dly = height/2;
早餐做什么简单又好吃QLabel *label = new QLabel(this);
label->tText("请点击⼗字叉校准触摸屏");
QFont ft;
ft.tPointSize(30);
label->tFont(ft);
QPalette pe;
pe.tColor(QPalette::WindowText, Qt::white);
label->tPalette(pe);
label->adjustSize();
label->size().width();
label->move((width - label->size().width())/2, (height / 4));
int dx = width / 10;
int dy = height / 10;
QPoint *points = data.screenPoints;
points[QWSPointerCalibrationData::TopLeft] = QPoint(dx, dy);
points[QWSPointerCalibrationData::BottomLeft] = QPoint(dx, height - dy);
points[QWSPointerCalibrationData::BottomRight] = QPoint(width - dx, height - dy);    points[QWSPointerCalibrationData::TopRight] = QPoint(width - dx, dy);
points[QWSPointerCalibrationData::Center] = QPoint(width / 2, height / 2);
pressCount = 0;
}
Calibration::~Calibration()
{
}
int Calibration::exec()
{
QWSServer::mouHandler()->clearCalibration();
grabMou();
activateWindow();
int ret = QDialog::exec();
releaMou();
return ret;
}
void Calibration::paintEvent(QPaintEvent*)
{//画⼗字+
QPainter p(this);
p.fillRect(rect(), Qt::black);
QPoint point = data.screenPoints[pressCount];
// Map to logical coordinates in ca the screen is transformed
QSize screenSize(qt_screen->deviceWidth(), qt_screen->deviceHeight());
point = qt_screen->mapFromDevice(point, screenSize);
#if 0
//⼗字横线
p.fillRect(point.x() - 6, point.y() - 1, 13, 3, Qt::red);
//⼗字竖线
p.fillRect(point.x() - 1, point.y() - 6, 3, 13, Qt::red);
#el
摘拼音
//设置pWigth 和 pPreWigth调节⼗字叉⼤⼩ , pWigth 必须⽐ pPreWigth⼤
//pPreWigth ⼗字外部直⾓边长度
//pPreWigth ⼗字外部直⾓边长度
/
/pWigth (⼗字宽度-1)/2
int pPreWigth = 5;
int pWigth = 21;
p.fillRect(point.x() - (pWigth-1), point.y() - (pWigth-1), pPreWigth, 1, Qt::white);
p.fillRect(point.x() + (pWigth-pPreWigth) , point.y() - (pWigth-1), pPreWigth, 1, Qt::white);    p.fillRect(point.x() - pWigth, point.y() - 1, pWigth*2+1, 3, Qt::white);
p.fillRect(point.x() - (pWigth-1), point.y() + (pWigth-1), pPreWigth, 1, Qt::white);
黄疸什么症状
p.fillRect(point.x() + (pWigth-pPreWigth) , point.y() + (pWigth-1), pPreWigth, 1, Qt::white);
p.fillRect(point.x() - (pWigth-1), point.y() - (pWigth-1), 1, pPreWigth, Qt::white);
p.fillRect(point.x() - (pWigth-1), point.y() + (pWigth-pPreWigth), 1, pPreWigth, Qt::white);    p.fillRect(point.x() - 1,  point.y() - pWigth, 3, pWigth*2+1, Qt::white);
p.fillRect(point.x() + (pWigth-1), point.y() - (pWigth-1), 1, pPreWigth, Qt::white);
p.fillRect(point.x() + (pWigth-1), point.y() + (pWigth-pPreWigth), 1, pPreWigth, Qt::white); #endif
}
白灼鱿鱼的做法void Calibration::mouReleaEvent(QMouEvent *event)
{
// Map from device coordinates in ca the screen is transformed
QSize screenSize(qt_screen->width(), qt_screen->height());
QPoint p = qt_screen->mapToDevice(event->pos(), screenSize);
项脊轩志赏析data.devPoints[pressCount] = p;
if (++pressCount < 5)
repaint();
el
accept();
}
void Calibration::accept()
{
Q_ASSERT(pressCount == 5);
QWSServer::mouHandler()->calibrate(&data);
QDialog::accept();
}
调⽤⽅法:
void  execCalibration()
{
qDebug()<<"Calibration start ...";
Calibration cal;
<();
qDebug()<<"Calibration end ...";
//数据保存到qt_pointercal中
QMessageBox::StandardButton rb = QMessageBox::information(NULL, "Title", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);  if(rb == QMessageBox::Yes)
{
qDebug()<<"save to pointeral";
QFile rfile("/opt/qt_pointercal");
if(rfile.open(QIODevice::ReadOnly))
{
QString data;
char buff[512];
data=buff;
qDebug()<<data;
QFile wfile("/opt/pointercal");
wfile.open(QIODevice::WriteOnly);
wfile.Latin1(), data.length());
wfile.clo();
rfile.clo();
}
}
}
注意:qt程序启动时根据tslib的环境变量TSLIB_CALIBFILE 指定的⽂件加载校准⽂件,
⽽上⾯实现的qt会保存校准数据到POINTERCAL_FILE指定的⽂件中,校验完以后要把
POINTERCAL_FILE指定的⽂件内容拷贝到TSLIB_CALIBFILE 中
POINTERCAL_FILE=/opt/qt_pointercal
TSLIB_CALIBFILE=/opt/pointercal

本文发布于:2023-07-27 18:26:10,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1098997.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:校准   保存   字叉   指定   程序   毛尖   黄疸   鱿鱼
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图