0

I tried adapting/understanding how this topic could help me with my video not fitting properly on my QGraphicsView but no success. I tried using the fitInView and override resizeEvent:

import os
from PyQt5 import QtCore, QtGui, QtWidgets, QtMultimedia, QtMultimediaWidgets

class Widget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(Widget, self).__init__(parent)

        self._scene = QtWidgets.QGraphicsScene(self)
        self._gv = QtWidgets.QGraphicsView(self._scene)

        self._videoitem = QtMultimediaWidgets.QGraphicsVideoItem()
        self._scene.addItem(self._videoitem)

        self._player = QtMultimedia.QMediaPlayer(self, 
                                                 QtMultimedia.QMediaPlayer.VideoSurface)
        self._player.stateChanged.connect(self.on_stateChanged)
        self._player.setVideoOutput(self._videoitem)

        file =  os.path.join("IMG_0479.MOV")
        self._player.setMedia(QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile(file)))
        button = QtWidgets.QPushButton("Play")
        button.clicked.connect(self._player.play)

        self.resize(640, 480)
        lay = QtWidgets.QVBoxLayout(self)
        lay.addWidget(self._gv)
        lay.addWidget(button)



    @QtCore.pyqtSlot(QtMultimedia.QMediaPlayer.State)
    def on_stateChanged(self, state):
        if state == QtMultimedia.QMediaPlayer.PlayingState:
            self._gv.fitInView(self._videoitem, QtCore.Qt.KeepAspectRatio)

    def resizeEvent(self, event):
        bounds = QtCore.QRectF(self._scene.sceneRect())
        self._gv.fitInView(bounds, QtCore.Qt.KeepAspectRatio)
        self._gv.centerOn(bounds.center())

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = Widget()
    w.show()
    sys.exit(app.exec_())

I am a bit lost/confused what needs to be done here in order to have the video being displayed fully in the QGraphicsView/Scene.

[EDIT] I amended the resizeEvent, and now the video is displayed over the full View AFTER I resize the window manually. However, even after resizing, the video is still cropped compared to the original.

Before resizing the window: enter image description here

After resizing the window: enter image description here

Original video using QuickTime: enter image description here

[EDIT2] Here is the link to the video (I trimmed it a little...Video.MOV

Hotone
  • 431
  • 3
  • 18
  • According to the first image, the video only shows part of the frame (Does everyone show the same video? It seems not since the first and third images should show the same frame). Could you share the .mov – eyllanesc May 27 '20 at 13:53
  • I added a light version of the video at the end of the original post, thanks! – Hotone May 27 '20 at 14:36
  • I converted the file .MOV into an .mp4 and now the video is not cropped, hence I guess it is an issue with how the GraphicsVideoItem is handling .MOV file (?) However I still need to resize the window with my mouse in order to have the video properly fitted onto the scene/view – Hotone May 28 '20 at 09:45

0 Answers0