-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.cpp
62 lines (45 loc) · 1.19 KB
/
widget.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "widget.h"
#include "ui_widget.h"
#include "qpainter.h"
#include "qpoint.h"
#include "QDebug"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
m_player = new VideoPlayer;
connect(m_player,SIGNAL(sig_GetOneFrame(QImage)),this,
SLOT(slotGetOneFrame(QImage)));
m_player->setFileName("cuc_ieschool.flv");
m_player->startPlay();
}
void Widget::run()
{
//m_player->startPlay();
}
void Widget::slotGetOneFrame(QImage img)
{
qDebug()<<"jieshou...";
mImage = img;
update(); //调用update将执行 paintEvent函数
qDebug()<<"chonghui wancheng...";
}
void Widget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setBrush(Qt::black);
painter.drawRect(0, 0, this->width(), this->height()); //先画成黑色
if (mImage.size().width() <= 0) return;
///将图像按比例缩放成和窗口一样大小
QImage img = mImage.scaled(this->size(),Qt::KeepAspectRatio);
int x = this->width() - img.width();
int y = this->height() - img.height();
x /= 2;
y /= 2;
painter.drawImage(QPoint(x,y),img); //画出图像
}
Widget::~Widget()
{
delete ui;
}