PDA

View Full Version : QPixmap and QPaint и QMediaPlayer



dmig2006
14th March 2016, 12:32
Hello,

I have a videocamera whose generated video to in h264. Picture to be drawn over the video. With this problem.
Я имею видеокамеру, которая генерирует видеопоток в h264. Картинка должна рисоваться поверх видео. С этим проблемма.

test.h


#ifndef TEST_H
#define TEST_H

#include <QWidget>
#include <QPainter>
#include <QPicture>
#include <QVideoWidget>
#include <QImage>

namespace Ui {
class Test;
}

struct Graphics {
QImage pixmapLogo;
};

class Test : public QVideoWidget
{
Q_OBJECT

Ui::Test *ui;
QPixmap mPixmap;
QImage pixmapL;
Graphics mGraphics;

protected:
void paintEvent(QPaintEvent *);

public:
Test(QWidget *parent = 0);
~Test();
};

#endif // TEST_H


test.cpp


#include "test.h"
#include "ui_test.h"

Test::Test(QWidget *parent) :
QVideoWidget(parent), ui(new Ui::Test)
{
ui->setupUi(this);

QPixmap p("://logo.png");
QLabel *label = new QLabel(parent);
label -> resize(150,34);
label -> setPixmap(p);
label -> move(610,14);
}

Test::~Test()
{
delete ui;
}

mainwindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QDataStream>
#include "test.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);
~MainWindow();

private:
Ui::MainWindow *ui;
Test *pTest;
QMediaPlayer *player;

#endif // MAINWINDOW_H


mainwindow.cpp


#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
player = new QMediaPlayer(this);//, QMediaPlayer::StreamPlayback);
pTest = new Test(this);
pTest -> setGeometry(5,35,1385,1040);
pTest -> setOptWidget(mOptWidget);
pTest -> hide();
player -> setVideoOutput(pTest);
}

Here the picture is displayed as it should
Картинка выводится поверх видео

if you write the following test.cpp
Если test.cpp написать следующим образом

test.cpp


#include "test.h"
#include "ui_test.h"

Test::Test(QWidget *parent) :
QVideoWidget(parent), ui(new Ui::Test)
{
ui->setupUi(this);
mGraphicsBlack.pixmapLogo.load(":/logo.png");
mGraphics = mGraphicsBlack;
pixmapL = mGraphics.pixmapLogo;
}

Test::~Test()
{
delete ui;
}

void Test::paintEvent(QPaintEvent *event)
{
QVideoWidget::paintEvent(event);
QPainter painter(this);
painter.drawImage(1010, 14, pixmapL);
painter.end();
}

Pictures do not have top stream. Why QPixmap it displays picture, QPaint it not dispalys picture?
Картинка не рисуется поверх видео. Почему QPixmap рисует картинку поверх видео а QPaint нет?
Как сделать чтобы QPaint рисовал картинку поверх видео? Чтобы и видео, и картинка отображались .

Get out of line in mainwindow.cpp :

player -> setVideoOutput(pTest);
Here the picture is displays, with the help QPaint.


При убирании строчки в mainwindow.cpp:

player -> setVideoOutput(pTest);
Картинка рисуется при помощи QPaint.

Why is there so? How to make the output video image over using QPaint? How to make a video stream is excreted in the picture?
Почему так? Как сделать чтобы отображалось видео в h264 и рисовалась картинка через QPaint? Как сделать чтобы и видео и картинка рисовались?