#include "widget.h"
#include <QHBoxLayout>
#include <QFileDialog>
#include <qdebug.h>
#include <mylabel.h>
#include "controlwgt.h"
#include <QGuiApplication>
#include <QScreen>
#include <QApplication>
#include <QDesktopWidget>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
Init();
}
Widget::~Widget()
{
}
void Widget::Init()
{
CreateToolWgt();
m_pImageLabel=new QLabel(this);
m_pImageLabel->setStyleSheet("background:white");
QVBoxLayout *mainLayout=new QVBoxLayout(this);
mainLayout->addWidget(m_pToolWgt);
mainLayout->addWidget(m_pImageLabel);
mainLayout->setSpacing(0);
mainLayout->setMargin(0);
this->setLayout(mainLayout);
this->resize(800,500);
}
void Widget::CreateToolWgt()
{
m_pOpenBtn=new QPushButton(tr("Open Image"),this);
m_pOpenBtn->setFixedSize(80,37);
m_pEditBoxBtn=new QPushButton(tr("Text Box"),this);
m_pEditBoxBtn->setFixedSize(80,37);
m_pSaveImage=new QPushButton(tr("Save Image"),this);
m_pSaveImage->setFixedSize(80,37);
m_pToolWgt=new QWidget(this);
QHBoxLayout *toolLayout=new QHBoxLayout(this);
toolLayout->addWidget(m_pOpenBtn);
toolLayout->addWidget(m_pEditBoxBtn);
toolLayout->addWidget(m_pSaveImage);
toolLayout->addStretch();
toolLayout->setMargin(0);
toolLayout->setSpacing(5);
m_pToolWgt->setLayout(toolLayout);
m_pToolWgt->setFixedHeight(50);
connect(m_pOpenBtn,&QPushButton::clicked,this,&Widget::onOpenClicked);
connect(m_pEditBoxBtn,&QPushButton::clicked,this,&Widget::onEditBoxClicked);
connect(m_pSaveImage,&QPushButton::clicked,this,&Widget::onSaveImage);
}
void Widget::closeEvent(QCloseEvent *event)
{
}
void Widget::onOpenClicked()
{
QString strPath=QFileDialog::getOpenFileName(this,"","","JPG(*.jpg);;PNG(*.png)");
QPixmap pixMap(strPath);
m_pImageLabel->setPixmap(pixMap);
}
void Widget::onEditBoxClicked()
{
QPoint globalPos = this->mapToGlobal(QPoint(0,0));//父窗口绝对坐标
int x = globalPos.x() + (this->width() - this->width()) / 2;//x坐标
int y = globalPos.y() + (this->height() - this->height()+100) / 2;//y坐标
myLabel *textLabel=new myLabel(this);
textLabel->move(x,y);
controlWgt *m_pControlWgt=new controlWgt(this);
m_pControlWgt->move(this->width(),this->height()/2);
textLabel->show();
m_pControlWgt->show();
connect(m_pControlWgt,&controlWgt::sSendTextFont,textLabel,&myLabel::ReceiverTextFont);
connect(m_pControlWgt,&controlWgt::sSendText,textLabel,&myLabel::ReceiverText);
connect(m_pControlWgt,&controlWgt::sSendOk,textLabel,&myLabel::ReceiverOK);
connect(textLabel,&myLabel::sSendMessage,this,&Widget::ReceiverMessage);
}
void Widget::ReceiverMessage(QString i_text, QString i_fraimly, int i_size)
{
controlWgt *m_pControlWgt=new controlWgt(this);
m_pControlWgt->move(this->width(),this->height()/2);
m_pControlWgt->SetText(i_text);
m_pControlWgt->SetFamily(i_fraimly);
m_pControlWgt->SetFontSize(i_size);
m_pControlWgt->show();
}
void Widget::onSaveImage()
{
QString strPath = QDir::currentPath();
QRect rect =QRect(this->pos().x(), this->pos().y()+160, this->width(), this->height());
QString strFileName = "Data";
strFileName = strPath + "/" + strFileName;
strFileName += ".png";
QScreen *screen = QGuiApplication::primaryScreen();
screen->grabWindow(QApplication::desktop()->winId(), rect.x(), rect.y(), rect.width(), rect.height()).save(strFileName, "png");
}
没有合适的资源?快使用搜索试试~ 我知道了~
ImageDeal.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共9个文件
cpp:4个
h:3个
user:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 50 13 下载量 118 浏览量
2021-02-24
10:17:50
上传
评论
收藏 9KB ZIP 举报
温馨提示
对图片进行处理,只实现在图片上进行添加文字的效果
资源详情
资源评论
资源推荐
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 9 条
- 1
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![avatar](https://profile-avatar.csdnimg.cn/12a03b47bf9d40f39e78a4a2de43db4f_weixin_43676892.jpg!1)
加油吧,小杜
- 粉丝: 2580
- 资源: 26
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
评论0