资源简介
由于项目要涉及芯片检测的功能,需要选择特定区域,所以制作了个区域选择框,在QWidget上绘制区域框,可以放大缩小移动,可以是矩形,也可以是椭圆,注释非常完整。
需要详细介绍的可以参考我的博客https://blog.csdn.net/qq_40732350/article/details/103538593
需要详细介绍的可以参考我的博客https://blog.csdn.net/qq_40732350/article/details/103538593

代码片段和文件信息
#include “DrawQWidget.h“
#include
#include
DrawQWidget::DrawQWidget(QWidget *parent) : QWidget(parent)
{
setAttribute(Qt::WA_styledBackground);
setstyleSheet(“background-color: rgb(0 0 0);“);
grabKeyboard();
setMouseTracking(true);
m_difference_x = 0;
m_difference_y = 0;
draw_shap = DRAW_NO;
painter = new QPainter(this);
frame_pen = QPen(QColor(0174255)2);
red_point_pen = QPen(QColor(25500)4);
is_mouse_pressed = false;
timer_id = startTimer(20);
rect_init_region();
ellipse_init_region();
/// 开启鼠标实时追踪
setMouseTracking(true);
}
DrawQWidget::~DrawQWidget()
{
killTimer(timer_id);
}
/* Event function
*
*/
void DrawQWidget::timerEvent(QTimerEvent *)
{
this->update();
}
void DrawQWidget::paintEvent(QPaintEvent *)
{
painter->begin(this);
painter->drawImage(QRectF(00width()height()) picture_image);
switch (draw_shap) {
case (DRAW_RECT) :{
painter->setPen(frame_pen);//绘制边框线
painter->drawRect(QRect(rect_left rect_top rect_width rect_height));
painter->setPen(red_point_pen);//绘制八个点
painter->drawPoints(rect_polygon);
}break;
case (DRAW_ELLIPSE) :{
painter->setPen(frame_pen);//绘制边框线
painter->drawEllipse(QRect(ellipse_left ellipse_top ellipse_width ellipse_height));
painter->setPen(red_point_pen);//绘制四个点
painter->drawPoints(ellipse_polygon);
}break;
case (DRAW_NO) :break;
}
painter->end();
}
void DrawQWidget::mousePressEvent(QMouseEvent *event)
{
// if (!is_start_draw) return;
is_mouse_pressed = true;
}
void DrawQWidget::mouseMoveEvent(QMouseEvent *event)
{
// if (!is_start_draw) return;
new_mouse_pos = event->pos();
if (is_mouse_pressed) {
m_difference_x = new_mouse_pos.x() - old_mouse_pos.x();
m_difference_y = new_mouse_pos.y() - old_mouse_pos.y();
switch (draw_shap) {
case (DRAW_RECT) :rect_change_region();break;
case (DRAW_ELLIPSE) :ellipse_change_region();break;
case (DRAW_NO) :break;
}
}else{
switch (draw_shap) {
case (DRAW_RECT) :rect_mouse_pos = rect_get_mouse_pos(new_mouse_pos.x() new_mouse_pos.y());break;
case (DRAW_ELLIPSE) :ellipse_mouse_pos = ellipse_get_mouse_pos(new_mouse_pos.x() new_mouse_pos.y());break;
case (DRAW_NO) :break;
}
}
old_mouse_pos = new_mouse_pos;
}
void DrawQWidget::mouseReleaseEvent(QMouseEvent *event)
{
// if (!is_start_draw) return;
is_mouse_pressed = false;
}
/* Rect function
*
*/
void DrawQWidget::rect_init_region()
{
rect_left = 100;
rect_top = 200;
rect_width = 101;
rect_h
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-12-14 14:05 unti
文件 10696 2019-12-14 13:44 unti
文件 4763 2019-12-14 13:42 unti
文件 175 2019-12-14 13:38 unti
文件 413 2019-12-14 13:41 unti
文件 18492 2019-12-14 13:38 unti
文件 830 2019-12-14 13:47 unti
文件 404 2019-12-14 13:44 unti
文件 1314 2019-12-14 13:44 unti
- 上一篇:斯坦福兔.7z点云扫描文件 pcd格式
- 下一篇:人脸检测.sln
相关资源
- vtk QT做的三维地质可视化系统2of2
- Qt局域网聊天软件
- Qt Creator opengl实现四元数鼠标控制轨迹
- QT局域网聊天系统(基于QT5.修改过)
- qt-电子点菜系统
- C 餐厅叫号系统(QT平)
- QT 实现文件下载
- qt图像处理
- 画图程序MFC/VC/VC CRectTracker 串行化
- QT,JPEG解码源代码(已完成)
- 用MFC实现简单的画图功能
- VC 6.0 MFC做画图软件
- Qt 播放音频文件
- Qt 读取16进制的data文件
- MQTT+串口(usart)透传
- 易语言QQTEA算法源码
- VC工程转Qt工程文件的工具
- MQTT推送Demo
- Scrach 画图.sb
- 基于Linux、QT的视频监控系统的设计与
- Qt 百度地图 定位
- QT酷炫界面开发指南《QmlBook》
- raphael画各种简单的图形都可以拖动
- Ubuntu下操作Excel,qt代码
- Qt图片浏览器 --基于Qt的Graphics View f
- qtnribbon2破解
- Qt软件开发 完整项目代码
- delphi 画图撤销控件
- fastlib——十分好用的画图工具
- MQTT_3.1protocol_Specific中文版
评论
共有 条评论