资源简介
QLabel 加载图片并绘制矩形图案 发出起始和结束的坐标
代码片段和文件信息
#include “processpic.h“
#include “ui_processpic.h“
#include
processPic::processPic(QWidget *parent) :
QWidget(parent)
ui(new Ui::processPic)
{
isMove = false;
ui->setupUi(this);
setBackGroundPic(“10101“);
ui->label->setScaledContents(true);//填充物资信息
ui->label->installEventFilter(this); //注册事件
}
processPic::~processPic()
{
delete ui;
}
void processPic::setBackGroundPic(QString path)
{
picPath = QCoreApplication::applicationDirPath()+“/image/“+path+“_1.jpg“;
}
void processPic::mousePressEvent(QMouseEvent *event)
{
startPoint = event->pos();
movePoint.setX(0);
movePoint.setY(0);
endPoint = QPoint(00);
emit pressPoint(startPoint);
}
void processPic::mouseMoveEvent(QMouseEvent *event)
{
movePoint = event->pos();
isMove = true;
emit mobilePoint(movePoint);
}
void processPic::mouseReleaseEvent(QMouseEvent *event)
{
endPoint = event->pos();
isMove = true;
emit releasePoint(event->pos());
}
bool processPic::eventFilter(Qobject *watched QEvent *event)
{
if(watched == ui->label && event->type() == QEvent::Paint)
{
QPainter Painter(ui->label);
QPixmap img1 = QPixmap(picPath);
Painter.begin(ui->label);
Painter.drawPixmap(00ui->label->width()img1.height()img1);
if(isMove &&( movePoint.x()!=0 || movePoint.y()!=0))
{
Painter.setPen(QPen(Qt::red1Qt::SolidLine));//设置画笔形式
Painter.drawRect(startPoint.x()startPoint.y()movePoint.x()-startPoint.x()movePoint.y()-startPoint.y());
}
update();
Painter.end();
return false;
}
return QWidget::eventFilter(watchedevent);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1803 2018-08-22 15:03 processpic.cpp
文件 883 2018-08-22 14:23 processpic.h
文件 615 2018-08-22 10:05 processpic.ui
- 上一篇:浪潮服务器管理网配置梳理
- 下一篇:四轮全向机器人的设计与控制方法
评论
共有 条评论