Video display in PySIde6
Unsolved
General and Desktop
-
Hello,
I have this class to display a video in PySide6 application:
class VideoPlayer(QGraphicsView): def __init__(self, video_path: str): super().__init__() # Create a scene self.scene = QGraphicsScene(self) self.setScene(self.scene) # Create video item and add to scene self.graphics_video_item = QGraphicsVideoItem() self.scene.addItem(self.graphics_video_item) # Create media player and set video output self.player = QMediaPlayer() self.player.setVideoOutput(self.graphics_video_item) self.player.setSource(QUrl.fromLocalFile(video_path)) def resizeEvent(self, event): """Ensure the video resizes properly when the window resizes.""" super().resizeEvent(event) self.fitInView(self.graphics_video_item, Qt.KeepAspectRatio) def play(self): self.player.play()
And when app starts, the Instance of the class is added to viewer's layout (green background), which is a QFrame. The video looks like this:
Now I have few problems I can't solve:
- I Can't figure how to make video fit the parent frame (green background), when app starts. If I resize window, then video fits the frame, but not initially.
- After resizing how can I make video corners respect container frame's rounded corner shape?
- How can I make video to fill the background, and don't leave the margins as shown here:
If you think I should be using totally different widgets/approach to display video with described goals, please let me know as well.
Thanks!
-
Hi,
- one thing that comes to mind is to trigger the fit in view with showEvent as well
- Do you mean the QFrame that contains your QGraphicsView ?
- Modify the margin/spacing of the layout