PDA

View Full Version : How to make a transparent QWidget over a Phonon Video?



linus
16th March 2010, 12:15
Hi!

Om working on a project thats showing a mpeg-file using phonon. I would like to place a transparent QWidget over my video so i can click and paint on it. I managed to put a QWidget above the video and i can click with the mouse and paint on it but its not transparent.

Any ideas how to make it transparent?

Heres my Overlay QWidget:



#include <QtGui>
#include "videoarea.h"

VideoArea::VideoArea(QWidget *parent) :
QWidget(parent)
{
this->setWindowOpacity(1.0);
}
void VideoArea::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
qDebug("Mouse click: X: %d Y: %d", event->x(), event->y());
crossList.append(QPoint(event->x(), event->y()));
paintCross();
}
}

void VideoArea::paintCross()
{
update();
}


void VideoArea::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(QPen(Qt::red, 1, Qt::DashDotLine, Qt::RoundCap));

for (int i = 0; i < crossList.size(); ++i)
{
painter.drawLine(crossList.at(i).x(), crossList.at(i).y()+10, crossList.at(i).x(), crossList.at(i).y()-10);
painter.drawLine(crossList.at(i).x()+10, crossList.at(i).y(), crossList.at(i).x()-10, crossList.at(i).y());
}
}

zgulser
16th March 2010, 12:21
try pen.setColor(Qt::transparent);

aamer4yu
16th March 2010, 12:30
Why dont you override the video widget itself ? You will need to call the base class paintEvent first and then your lines drawing code.
That way you can still draw over the video, isnt it :rolleyes:

linus
16th March 2010, 12:48
Why dont you override the video widget itself ? You will need to call the base class paintEvent first and then your lines drawing code.
That way you can still draw over the video, isnt it :rolleyes:

I did this first but it didnt work, all i saw was the videostream.

linus
16th March 2010, 12:52
try pen.setColor(Qt::transparent);

On my painter? I tried it and all it did was to make my painting transparent, not the background.

zgulser
16th March 2010, 13:33
Pardon me,

what about widget->setStyleSheet("background-color: rgb(0,0,0,0)"); ?

You can do it from the designer as well.

aamer4yu
16th March 2010, 13:34
I did this first but it didnt work, all i saw was the videostream.
I guess it might be tricky. I guess the phonon will use directX and directX will render directly on memory buffer,,, so am afraid you cant do it directly.. I will try if i get some time...
till then hope someone else comes to rescue :)

linus
16th March 2010, 13:46
I guess it might be tricky. I guess the phonon will use directX and directX will render directly on memory buffer,,, so am afraid you cant do it directly.. I will try if i get some time...
till then hope someone else comes to rescue :)

Ok, thanks. Appreciate it!

linus
16th March 2010, 14:27
Pardon me,

what about widget->setStyleSheet("background-color: rgb(0,0,0,0)"); ?

You can do it from the designer as well.

I tried it and it didnt work, thanks anyway.