资源简介
QT实现图片自定义截取功能类似QQ上传头像时的截取功能,截取完毕的图片会存于当前目录下
代码片段和文件信息
#include “cutdialog.h“
#include
CutDialog::CutDialog(QWidget *parent) :m_isMoving(false) m_mouse_down(false)
Qframe(parent) m_left(false) m_right(false) m_top(false) m_bottom(false)
{
setWindowFlags(Qt::framelessWindowHint);
setMouseTracking(true);
setGeometry(00200200);
cutpic.load(“:/images/z_45_78.png“);
label = new QLabel(this);
if(!cutpic.isNull()){
label->setPixmap(cutpic.scaled(label->width()label->height()));
}
else{
label->setText(“is NULL“);
}
QGridLayout *layout = new QGridLayout(this);
layout->addWidget(label);
layout->setMargin(0);
setLayout(layout);
label->setMouseTracking(true);
}
CutDialog::~CutDialog()
{
}
void CutDialog::resizeEvent(QResizeEvent *event)
{
label->setPixmap(cutpic.scaled(label->width()label->height()));
}
void CutDialog::mousePressEvent(QMouseEvent * event)
{
m_startPoint = event->pos();
m_mouse_down = event->button() == Qt::LeftButton;
}
//画白色虚线
void CutDialog::paintEvent(QPaintEvent *event)
{
QPainter paint(this);
QPen pen;
QVector dashes;
qreal space = 3;
dashes << 5 << space << 5 < pen.setDashPattern(dashes);
pen.setColor(Qt::white);
paint.setPen(QColor(54158254120));
paint.drawRect(11width()-3height()-3);
paint.setPen(pen);
int x_pos = (int) width()/3.0;
int y_pos = (int) height()/3.0;
paint.drawLine(x_pos 1 x_pos height());
paint.drawLine(2*x_pos 1 2*x_pos height());
paint.drawLine(1 y_pos width() y_pos);
paint.drawLine(1 2*y_pos width() 2*y_pos);
}
QRect CutDialog::getResizeGem(QRect oldgeo QPoint mousePoint)
{
QRect g = oldgeo;
bool lorr = m_left | m_right;
bool torb = m_top | m_bottom;
int dx = mousePoint.x() - m_startPoint.x();
int dy = mousePoint.y() - m_startPoint.y();
if(lorr && torb)
{
int maxLen = qMin(qAbs(dx)qAbs(dy));
if(m_left && m_top && dx*dy >0)
{
g.setLeft(dx >0 ?g.left() + maxLen : g.left() - maxLen);
g.setTop(dy >0? g.top() + maxLen : g.top() - maxLen);
}
if(m_right && m_top && dx*dy < 0)
{
g.setRight(dx>0 ? g.right() + maxLen:g.right() - maxLen);
g.setTop(dy >0? g.top() + maxLen : g.top() - maxLen);
}
if(m_right && m_bottom && dx*dy > 0)
{
g.setRight(dx>0 ? g.right() + maxLen:g.right() - maxLen);
g.setBottom(dy >0? g.bottom() + maxLen : g.bottom() - maxLen);
}
if(m_left && m_bottom && dx*dy < 0)
{
g.setLeft(dx >0 ?g.left() + maxLen : g.left() - maxLen);
g.setBottom(dy >0? g.bottom() + maxLen : g.bottom() - maxLen);
}
return g;
}
else if(lorr)
{
if(m_left)
g.setLeft(g.left() + dx);
if(m_right)
g.setRight(g.right() + dx);
int len = g.width() - oldgeo.width();
int intHight = (int) len/2.0;
g.setTop(g.top() - intHight);
g.setBottom(g.bottom() + len - intHight);
}
else if(torb)
{
if(m_bottom)
g.setBottom(g.bottom() + dy);
if(m_top)
g.setTop(g.top() + dy);
int dhei
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-04-01 16:32 HeadPicCut\
文件 4868 2016-04-01 15:47 HeadPicCut\cutdialog.cpp
文件 892 2015-02-27 17:39 HeadPicCut\cutdialog.h
文件 1048 2016-04-01 15:53 HeadPicCut\getheadpicture.cpp
文件 650 2016-04-01 15:42 HeadPicCut\getheadpicture.h
文件 2886 2016-04-01 16:30 HeadPicCut\getheadpicture.ui
文件 1070 2016-04-01 16:30 HeadPicCut\headpiccut.cpp
文件 398 2016-04-01 15:43 HeadPicCut\headpiccut.h
文件 584 2016-04-01 15:17 HeadPicCut\HeadPicCut.pro
文件 18030 2016-04-01 16:32 HeadPicCut\HeadPicCut.pro.user
文件 2836 2016-04-01 16:06 HeadPicCut\headpiccut.ui
目录 0 2016-04-01 15:55 HeadPicCut\images\
文件 97 2016-04-01 15:51 HeadPicCut\images.qrc
文件 19510 2015-02-27 14:50 HeadPicCut\images\z_45_78.png
文件 11649 2015-02-28 14:01 HeadPicCut\images\z_45_79.png
文件 183 2016-04-01 15:11 HeadPicCut\main.cpp
文件 776 2015-02-27 17:55 HeadPicCut\photoshotdialog.cpp
文件 359 2016-04-01 15:21 HeadPicCut\photoshotdialog.h
评论
共有 条评论