Results 1 to 9 of 9

Thread: How to make a transparent QWidget over a Phonon Video?

  1. #1
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to make a transparent QWidget over a Phonon Video?

    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:

    Qt Code:
    1. #include <QtGui>
    2. #include "videoarea.h"
    3.  
    4. VideoArea::VideoArea(QWidget *parent) :
    5. QWidget(parent)
    6. {
    7. this->setWindowOpacity(1.0);
    8. }
    9. void VideoArea::mousePressEvent(QMouseEvent *event)
    10. {
    11. if (event->button() == Qt::LeftButton) {
    12. qDebug("Mouse click: X: %d Y: %d", event->x(), event->y());
    13. crossList.append(QPoint(event->x(), event->y()));
    14. paintCross();
    15. }
    16. }
    17.  
    18. void VideoArea::paintCross()
    19. {
    20. update();
    21. }
    22.  
    23.  
    24. void VideoArea::paintEvent(QPaintEvent *)
    25. {
    26. QPainter painter(this);
    27. painter.setPen(QPen(Qt::red, 1, Qt::DashDotLine, Qt::RoundCap));
    28.  
    29. for (int i = 0; i < crossList.size(); ++i)
    30. {
    31. painter.drawLine(crossList.at(i).x(), crossList.at(i).y()+10, crossList.at(i).x(), crossList.at(i).y()-10);
    32. painter.drawLine(crossList.at(i).x()+10, crossList.at(i).y(), crossList.at(i).x()-10, crossList.at(i).y());
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: How to make a transparent QWidget over a Phonon Video?

    try pen.setColor(Qt::transparent);

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make a transparent QWidget over a Phonon Video?

    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

  4. #4
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make a transparent QWidget over a Phonon Video?

    Quote Originally Posted by aamer4yu View Post
    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
    I did this first but it didnt work, all i saw was the videostream.

  5. #5
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make a transparent QWidget over a Phonon Video?

    Quote Originally Posted by zgulser View Post
    try pen.setColor(Qt::transparent);
    On my painter? I tried it and all it did was to make my painting transparent, not the background.

  6. #6
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: How to make a transparent QWidget over a Phonon Video?

    Pardon me,

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

    You can do it from the designer as well.

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make a transparent QWidget over a Phonon Video?

    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

  8. #8
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make a transparent QWidget over a Phonon Video?

    Quote Originally Posted by aamer4yu View Post
    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!

  9. #9
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make a transparent QWidget over a Phonon Video?

    Quote Originally Posted by zgulser View Post
    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.

Similar Threads

  1. Playing video using Phonon video widget
    By Leolander in forum Newbie
    Replies: 0
    Last Post: 26th February 2010, 06:15
  2. Phonon Video + Transparent Label Problems
    By jftaylor21 in forum Qt Programming
    Replies: 2
    Last Post: 1st November 2009, 18:53
  3. Replies: 3
    Last Post: 5th July 2009, 17:22
  4. Video freezes during mpeg video playback using Phonon
    By davejames in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2009, 08:45
  5. Non-transparent QWidget on semi-transparent parent
    By EuroElessar in forum Qt Programming
    Replies: 0
    Last Post: 29th August 2008, 16:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.