I'm new to Qt and I'm having some troubles.
I'm trying to draw a simple line on a video, like an overlay, when i click on a button. My video is from a camera, and it is displayed into a QGraphicsScene (or Qframe), it's a live video.
I tried to modify the paintEvent, but the line emerges and disapear when a new frame comes.
I also tried to create an Overlay class, with some attributes (WA_NoBackGround and WA_PaintOnScreen), but this time the line emerges on the video, but the video stops.
Here is my code for the overlay ( inspired by Draw Rectangular overlay on QWidget at click ):
Overlay.h
#include <QApplication>
#include <QWidget>
#include <QPainter>
#include <QPointer>
class Overlay : public QWidget
{
public:
Overlay(QWidget * parent = 0) ;
protected:
void paintEvent(QPaintEvent *e );
};
Overlay.cpp
#include "overlay.h"
Overlay::Overlay(QWidget *parent): QWidget (parent)
{
//setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_NoBackground);
setAttribute(Qt::WA_PaintOnScreen);
}
void Overlay::paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.drawLine(0,0,100,100);
}
The clickDraw button slot :
QPointer<Overlay> m_overlay;
w= static_cast<QWidget*>(ui->r_frame);
if (!m_overlay)
m_overlay = new Overlay(w->parentWidget());
m_overlay->setGeometry(w->geometry());
m_overlay->show();
update();
I'm on linux embedded, with Qt 4.8.6
EDIT I tried to create a transparent Qwidget (setOpacity), with the QGraphicsView object as parent, but it did not work, the widget appears white. I think i need a composition manager for X11 (it is what i read from various websites).
Thanks for your help, Greetings