QVideoWidget and QStackedWidget creating problem in PySide6

618 Views Asked by At

I am trying to build a GUI using PySide6 on Windows 10 - Python V 3.10.2.

Basically, I wanted to create a vertical box on left with buttons to switch between the stacked widgets. And a video widget with play button & scroll bar on the right side with a stacked widget underneath the video widget. On the stacked widget, I intend to put some buttons which will link files to play on the video widget. The Problem: The video widget does works perfectly when commenting out the stacked widget. However, if I add the stacked widget, sound does play nicely but the videowidget can't be seen. See the code snippet below.

class mainwindow(QMainWindow):
    def __init__(self):
        super().__init__()
        
        self.audio = QAudioOutput()
        self.video = QVideoWidget()
        self.player = QMediaPlayer()
        self.player.setAudioOutput(self.audio)
        self.player.setVideoOutput(self.video)
        
        
        side_layout = QVBoxLayout()
        side_layout.addWidget(QLabel('First Label'))
        side_layout.addWidget(QPushButton('First Button'))
        # I have not named buttons for now for conciseness.
        
        vid_control_layout = QHBoxLayout()
        
        play_btn = QPushButton('Play')
        play_btn.clicked.connect(self.play_video)
        vid_control_layout.addWidget(play_btn)
        vid_control_layout.addWidget(QSlider(orientation = Qt.Horizontal))
        
        stack_widget = QStackedWidget()
        stack_widget.addWidget(QWidget())
        stack_widget.addWidget(QWidget())
        
        video_layout = QVBoxLayout()
        video_layout.addWidget(self.video)
        video_layout.addLayout(vid_control_layout)
        video_layout.addWidget(stack_widget)        
        
        mainlayout = QHBoxLayout()
        mainlayout.addLayout(side_layout)
        mainlayout.addLayout(video_layout)
        
        mainwidget = QWidget()
        mainwidget.setLayout(mainlayout)
        
        self.setCentralWidget(mainwidget)
        
    def play_video(self):
        self.player.setSource('111.mp4')
        self.player.play()


app = QApplication(sys.argv)
win = mainwindow()
win.show()
sys.exit(app.exec())

I am a self learner of Python and started learning PyQt5 quite recently. As there was too many version problem in PyQt5 and QMediaPlayer, I switched to PySide6.

Let me know if this detail will help in fixing the problem.

0

There are 0 best solutions below