python qt, display text/label above another widget(phonon)

后端 未结 1 1812
花落未央
花落未央 2021-01-03 15:06

I\'m making a video player using PySide which is a python bind to the Qt framework. I\'m using phonon(a module) to display the video and I want to display text above the vid

1条回答
  •  北海茫月
    2021-01-03 15:48

    If you just create your label and set the phonon widget as the parent, the label should appear over it.

    QLabel *label = new QLabel(phononWidget);
    label->setText("Text over video!");
    

    (I realize this is C++ and you are working in Python but it should be similar)

    Update: The above will not work for hardware accelerated video playback. An alternative that does work is to create a graphics scene and add the video widget or player to the scene and use a QGraphicsTextItem for the text. Setting the viewport to a QGLWidget will enable hardware acceleration:

    QGraphicsScene *scene = new QGraphicsScene(this);
    
    Phonon::VideoPlayer *v = new Phonon::VideoPlayer();
    v->load(Phonon::MediaSource("video_file"));
    
    QGraphicsProxyWidget *pvideoWidget = scene->addWidget(v);
    
    QGraphicsView *view = new QGraphicsView(scene);
    view->setViewport(new QGLWidget); //Enable hardware acceleration!
    
    QGraphicsTextItem *label = new QGraphicsTextItem("Text Over Video!", pvideoWidget);
    label->moveBy(100, 100);
    
    v->play();
    

    0 讨论(0)
提交回复
热议问题