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. Video display in PySIde6
Forum Updated to NodeBB v4.3 + New Features

Video display in PySIde6

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 214 Views 2 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.
  • I Offline
    I Offline
    irakli
    wrote on last edited by
    #1

    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:
    Screenshot 2025-02-19 213619.png

    Now I have few problems I can't solve:

    1. 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.
    2. After resizing how can I make video corners respect container frame's rounded corner shape?
    3. How can I make video to fill the background, and don't leave the margins as shown here:

    Screenshot 2025-02-19 214408.png

    If you think I should be using totally different widgets/approach to display video with described goals, please let me know as well.

    Thanks!

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

      Hi,

      1. one thing that comes to mind is to trigger the fit in view with showEvent as well
      2. Do you mean the QFrame that contains your QGraphicsView ?
      3. Modify the margin/spacing of the layout

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

      1 Reply Last reply
      0

      • Login

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