Issue
I am implementing a movie player inside pyside with ffmpeg. All works fine sending frames to the QImage buffer and I can stop and start OK using the python timer() function to control the playback rate EXCEPT I cannot work out how to pause. i.e., the pause button is a two state button that will play or pause, according to the state of the button when it is clicked in succession.
I set up the button :
self.pauseButton = QToolButton()
self.pauseButton.setCheckable(True)
Then, I thought the isDown() method would determine if the button is in it's up or down state, then send a signal to the timer() function I define elsewhere. The stop and play buttons start and stop the timer and image stream ok but this pause function pauses only :
if self.pauseButton.isDown():
self.pauseButton.clicked.connect(lambda: self.timer.start()))
else:
self.pauseButton.clicked.connect(lambda: self.timer.stop())
Where am I going wrong? Can PySide detect the QPushButton state or do I need to implement a separate Event filter with a button counter method or similar?
cheers!
Solution
To get the buttons state, use self.pauseButton.isChecked()
. To get the functionality I believe you are looking for, you will need to check the buttons state in the method that the button is connected to.
self.pauseButton.clicked.connect(self.button_assignment)
def button_assignment(self):
if self.pauseButton.isChecked():
self.timer.start()
else:
self.timer.stop()
The way your code is written, which ever state the button is in when it is initialized is what the clicked signal will connect to.
Also, the lambda statements you have in your clicked connection are not necessary. Just remove the parentheses from the function calls. self.pauseButton.clicked.connect(self.timer.stop)
Answered By - MalloyDelacroix
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.