Skip to content

Instantly share code, notes, and snippets.

@blackball
Created November 9, 2011 04:47
Show Gist options
  • Save blackball/1350424 to your computer and use it in GitHub Desktop.
Save blackball/1350424 to your computer and use it in GitHub Desktop.
//----------.h file ------------
#ifndef MYVIDEOWIDGET_H
#define MYVIDEOWIDGET_H
#include <QtOpenGL/QtOpenGL>
#include <QtGui/QImage>
class MyVideoWidget : public QGLWidget
{
Q_OBJECT
public:
explicit MyVideoWidget(QWidget *parent = 0);
void setFrame(const QImage frame);
protected:
void paintEvent(QPaintEvent *e);
void mouseDoubleClickEvent(QMouseEvent *e);
signals:
void dClicked();
private:
QImage frame;
};
#endif // MYVIDEOWIDGET_H
// --------------.cpp-------------
#include "myvideowidget.h"
#include <QtGui/QMouseEvent>
MyVideoWidget::MyVideoWidget(QWidget *parent) :
QGLWidget(parent)
{
}
void MyVideoWidget::setFrame(const QImage frame)
{
this->frame = frame;
// paint new frame
this->update();
}
void MyVideoWidget::paintEvent(QPaintEvent *e)
{
// set the painter to use a smooth scaling
QPainter p(this);
p.setRenderHint(QPainter::SmoothPixmapTransform,true);
p.drawImage(this->rect(), frame);
e->accept();
}
void MyVideoWidget::mouseDoubleClickEvent(QMouseEvent *e)
{
emit dClicked();
e->accept();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment