Results 1 to 3 of 3

Thread: Display QLabel above Phonon::VideoPlayer

  1. #1
    Join Date
    Mar 2011
    Location
    Moscow, Russia
    Posts
    11
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Display QLabel above Phonon::VideoPlayer

    Hi everybody! I have a little problem getting a QLabel (some text from a database) displayed above a video that is continuously played in Phonon::VideoPlayer widget. Both in windowed and fullscreen modes.

    The "standard procedure":
    Qt Code:
    1. QLabel *lbl = new QLabel(ui->videoPlayer); //same results with ui->videoPlayer->videoWidget() as parent
    2. lbl->setText("test");
    To copy to clipboard, switch view to plain text mode 

    does not work very well. Neither does placing VideoPlayer inside a QGraphicsView.

    So I'll be thankful if somebody could help solving this problem.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display QLabel above Phonon::VideoPlayer

    This won't work. Phonon rendering is done by an external engine so you can't put anything "on top" of it. You could try making the player and your label siblings (instead of parent and child) but you probably won't get a satisfactory result. I suggest you try with the new multimedia framework that comes with mobility 1.1. You shouldn't have problems there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    kefir (10th March 2011)

  4. #3
    Join Date
    Mar 2011
    Location
    Moscow, Russia
    Posts
    11
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Display QLabel above Phonon::VideoPlayer

    After trying lots and lots of variants...
    Here's the acceptable solution. The code is crude but I think it can help those who have similar problems.

    main.cpp
    Qt Code:
    1. #include "customproxy.h"
    2.  
    3. #include <phonon/mediaobject.h>
    4. #include <phonon/mediasource.h>
    5. #include <phonon/videowidget.h>
    6.  
    7.  
    8. #include <QtGui>
    9. #include <QtDebug>
    10. #include <QAbstractFileEngine>
    11.  
    12. #ifndef QT_NO_OPENGL
    13. #include <QGLWidget>
    14. #endif
    15.  
    16. int main(int argc, char *argv[])
    17. {
    18. Q_INIT_RESOURCE(videowall);
    19. QApplication app(argc, argv);
    20.  
    21.  
    22. Phonon::MediaObject *media = new Phonon::MediaObject();
    23. Phonon::VideoWidget *video = new Phonon::VideoWidget();
    24. CustomProxy *proxy = new CustomProxy(0, 0);
    25. Phonon::createPath(media, video);
    26. proxy->setWidget(video);
    27. QRectF rect = proxy->boundingRect();
    28. proxy->setPos(0, 0);
    29. proxy->show();
    30. scene.addItem(proxy);
    31.  
    32. media->setCurrentSource(QString("output22.avi"));
    33.  
    34. media->play();
    35.  
    36. QGraphicsTextItem *titem = scene.addText("Bla-bla-bla");
    37. titem->setPos(rect.width()/2, rect.height()/2);
    38.  
    39.  
    40. QGraphicsView view(&scene);
    41. #ifndef QT_NO_OPENGL
    42. view.setViewport(new QGLWidget);
    43. #endif
    44. view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    45. view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    46. view.show();
    47. view.setWindowTitle("Eternal fire");
    48. // view.showFullScreen();
    49.  
    50. return app.exec();
    51. }
    To copy to clipboard, switch view to plain text mode 

    customproxy.h
    Qt Code:
    1. #ifndef CUSTOMPROXY_H
    2. #define CUSTOMPROXY_H
    3.  
    4. #include <QGraphicsProxyWidget>
    5.  
    6. class CustomProxy : public QGraphicsProxyWidget
    7. {
    8. Q_OBJECT
    9. public:
    10. CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
    11.  
    12. QRectF boundingRect() const;
    13.  
    14.  
    15. protected:
    16. void resizeEvent(QGraphicsSceneResizeEvent *event);
    17.  
    18. private slots:
    19.  
    20. private:
    21.  
    22. };
    23.  
    24. #endif
    To copy to clipboard, switch view to plain text mode 

    customproxy.cpp
    Qt Code:
    1. #include "customproxy.h"
    2.  
    3. #include <QtGui>
    4.  
    5. CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
    6. : QGraphicsProxyWidget(parent, wFlags)
    7. {
    8. setCacheMode(NoCache);
    9. }
    10.  
    11. QRectF CustomProxy::boundingRect() const
    12. {
    13. return QGraphicsProxyWidget::boundingRect().adjusted(0, 0, 0, 0);
    14. }
    15.  
    16. void CustomProxy::resizeEvent(QGraphicsSceneResizeEvent *event)
    17. {
    18. //
    19. }
    To copy to clipboard, switch view to plain text mode 

    Use wisely, live long and prosper =)

    Special thanks to this article http://labs.qt.nokia.com/2008/11/28/videos-get-pimped/

    Also I've tried combining ffmpeg + sdl but unfortunately got stuck with SDL_Surface not willing to attach itself to QWidget. But that's another story)
    Last edited by kefir; 2nd April 2011 at 05:07.

  5. The following user says thank you to kefir for this useful post:

    cpscotti (6th May 2011)

Similar Threads

  1. Phonon::VideoPlayer
    By dano_labrosse in forum Newbie
    Replies: 6
    Last Post: 1st February 2012, 06:33
  2. QGraphicsEffect on a Phonon::VideoPlayer
    By scary_jeff in forum Newbie
    Replies: 3
    Last Post: 20th January 2011, 01:12
  3. How to set a background in a Phonon VideoPlayer ?
    By slimIT in forum Qt Programming
    Replies: 1
    Last Post: 24th October 2010, 21:54
  4. phonon VideoPlayer refresh
    By rbp in forum Qt Programming
    Replies: 6
    Last Post: 14th November 2008, 01:56
  5. phonon VideoPlayer seek
    By rbp in forum Qt Programming
    Replies: 4
    Last Post: 31st October 2008, 04:53

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.