Qt屏幕鼠标追踪

网友投稿 654 2022-11-30

Qt屏幕鼠标追踪

Qt屏幕鼠标追踪

通过鼠标移动事件获取

#include "recordwidget.h"#include "ui_recordwidget.h"#include #include #include #include #include #include #include #include #include #include RecordWidget::RecordWidget(QWidget *parent) : QWidget(parent), ui(new Ui::RecordWidget){ ui->setupUi(this); desktopWidget = QApplication::desktop(); QRect deskRect = desktopWidget->availableGeometry(); QRect screenRect = desktopWidget->screenGeometry(); g_nActScreenX = screenRect.width(); g_nActScreenY = screenRect.height(); this->move(QPoint(0,0)); this->resize(g_nActScreenX,g_nActScreenY); center = QPoint(g_nActScreenX/2,g_nActScreenY/2); connect(&timer,SIGNAL(timeout()),this,SLOT(accepttimeout())); timer.start(300);}RecordWidget::~RecordWidget(){ delete ui;}void RecordWidget::accepttimeout(){ POINT last_p; GetCursorPos(&last_p); pos = QPoint(last_p.x,last_p.y); update();}void RecordWidget::paintEvent(QPaintEvent *){ QPainter painter(this); QPen pen; pen.setColor("red"); painter.setPen(pen); painter.drawLine(center,pos);}void RecordWidget::mouseMoveEvent(QMouseEvent *event){}void RecordWidget::notify(QObject *obj, QEvent *e){ qDebug()<<"sssddd ";}

#ifndef WIDGET_H#define WIDGET_H#include #include #include #include #include namespace Ui {class RecordWidget;}class RecordWidget : public QWidget{ Q_OBJECTpublic: explicit RecordWidget(QWidget *parent = nullptr); ~RecordWidget();public slots: void accepttimeout();protected: void paintEvent(QPaintEvent *); void mouseMoveEvent(QMouseEvent *event); void notify(QObject *obj, QEvent *e);private: Ui::RecordWidget *ui; // 当前屏幕,用于截取当前像素 QString m_strFileName; // 100为1s uint m_Fps = 33; QPoint center; QPoint pos; QRect m_rectRecord; QDesktopWidget* desktopWidget; int g_nActScreenX; int g_nActScreenY; QTimer timer;};#endif // WIDGET_H

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:QSplitterWidget多窗口自动排列
下一篇:opencv 将Mat类型从CV_32F转CV_8U
相关文章

 发表评论

暂时没有评论,来抢沙发吧~