Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with QGraphicsScene and QVideoWidget in Qt5 (python2 pyside2)
Forum Updated to NodeBB v4.3 + New Features

Problem with QGraphicsScene and QVideoWidget in Qt5 (python2 pyside2)

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 896 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    orensbruli
    wrote on last edited by
    #1

    Hi!

    Can some one confirm if QVideoWidget is not working when added to a QGraphicsScene?
    When I try to run this code (set the path to some mp4 file) the video is not shown or played.

    import signal
    import sys
    
    from PySide2.QtCore import QUrl
    from PySide2.QtMultimedia import QMediaPlayer, QMediaPlaylist, QMediaContent
    from PySide2.QtMultimediaWidgets import QVideoWidget
    from PySide2.QtWidgets import QGraphicsScene, QGraphicsView, QApplication
    
    PATH='<set a mp4 video path here>'
    
    if __name__ == '__main__':
    	app = QApplication(sys.argv)
    	scene = QGraphicsScene()
    	view = QGraphicsView()
    	view.setScene(scene)
    	view.show()
    	media_player = QMediaPlayer()
    	video_widget = QVideoWidget()
    	current_play_list = QMediaPlaylist()
    	media_player.setVideoOutput(video_widget)
    	media_player.setPlaylist(current_play_list)
    	video_proxy = scene.addWidget(video_widget)
    	# video_widget.show()
    	current_play_list.addMedia(QMediaContent(QUrl.fromLocalFile(PATH)))
    	media_player.play()
    	signal.signal(signal.SIGINT, signal.SIG_DFL)
    	app.exec_()
    
    

    If I just comment the video_proxy = scene.addWidget(video_widget) line and uncomment the video_widget.show() the video is played as an independent widget witout problems. Can someone confirm this and maybe have any suggestion to fix it. I know that QGraphicsVideoItem exists but I wanted to have the playlist facilities that I have with QMediaPlaylist.

    import signal
    import sys
    
    from PySide2.QtCore import QUrl
    from PySide2.QtMultimedia import QMediaPlayer, QMediaPlaylist, QMediaContent
    from PySide2.QtMultimediaWidgets import QVideoWidget
    from PySide2.QtWidgets import QGraphicsScene, QGraphicsView, QApplication
    
    PATH='<set a mp4 video path here>'
    
    if __name__ == '__main__':
    	app = QApplication(sys.argv)
    	scene = QGraphicsScene()
    	view = QGraphicsView()
    	view.setScene(scene)
    	view.show()
    	media_player = QMediaPlayer()
    	video_widget = QVideoWidget()
    	current_play_list = QMediaPlaylist()
    	media_player.setVideoOutput(video_widget)
    	media_player.setPlaylist(current_play_list)
    	# video_proxy = scene.addWidget(video_widget)
    	video_widget.show()
    	current_play_list.addMedia(QMediaContent(QUrl.fromLocalFile(PATH)))
    	media_player.play()
    	signal.signal(signal.SIGINT, signal.SIG_DFL)
    	app.exec_()
    

    Thank you in advance.
    Best.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Based on QTBUG-35299, it can't work because of the use of a native handle for the QVideoWidget.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      O 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Based on QTBUG-35299, it can't work because of the use of a native handle for the QVideoWidget.

        O Offline
        O Offline
        orensbruli
        wrote on last edited by
        #3

        @SGaist thank you so much for your quick answer!

        1 Reply Last reply
        0
        • O Offline
          O Offline
          orensbruli
          wrote on last edited by orensbruli
          #4

          If somebody find the same problem than me, it can be partially solved using the QGraphicsVideoItem insted QVideoWidget. You can set the QMediaPlayer setVideoOutput to the QGraphicsVideoItem and everything works fine. You can also have all the QMediaPlaylist functionalities.

          The example code would be something like this:

          import signal
          import sys
          
          from PySide2.QtCore import QUrl
          from PySide2.QtMultimedia import QMediaPlayer, QMediaPlaylist, QMediaContent
          from PySide2.QtMultimediaWidgets import QVideoWidget, QGraphicsVideoItem
          from PySide2.QtWidgets import QGraphicsScene, QGraphicsView, QApplication
          
          PATH='<set a mp4 video path here>'
          
          if __name__ == '__main__':
          	app = QApplication(sys.argv)
          	scene = QGraphicsScene()
          	view = QGraphicsView()
          	view.setScene(scene)
          	view.show()
          	media_player = QMediaPlayer()
          	video_widget = QGraphicsVideoItem()
          	current_play_list = QMediaPlaylist()
          	media_player.setVideoOutput(video_widget)
          	media_player.setPlaylist(current_play_list)
          	video_proxy = scene.addItem(video_widget)
          	video_widget.show()
          	current_play_list.addMedia(QMediaContent(QUrl.fromLocalFile(PATH)))
          	media_player.play()
          	signal.signal(signal.SIGINT, signal.SIG_DFL)
          	app.exec_()
          
          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved