-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsrcimagewidget.cpp
More file actions
38 lines (34 loc) · 1.01 KB
/
Copy pathsrcimagewidget.cpp
File metadata and controls
38 lines (34 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "srcimagewidget.h"
#include "ui_srcimagewidget.h"
#include <QPainter>
SrcImageWidget::SrcImageWidget(QWidget *parent) :
QFrame(parent),
ui(new Ui::SrcImageWidget)
{
ui->setupUi(this);
setFrameStyle(QFrame::Panel|QFrame::Sunken);
}
SrcImageWidget::~SrcImageWidget()
{
delete ui;
}
void SrcImageWidget::paintEvent(QPaintEvent *event)
{
if(src && !src->isNull())
{
QPainter painter(this);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
QRect targetRect = rect();
QImage scaledImage = src->scaled(targetRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
QRect imageRect = QRect((targetRect.width() - scaledImage.width()) / 2,
(targetRect.height() - scaledImage.height()) / 2,
scaledImage.width(), scaledImage.height());
painter.drawImage(imageRect, scaledImage);
}
QFrame::paintEvent(event);
}
void SrcImageWidget::showPic(QImage *p)
{
src = p;
update();
}