May 2019
Intermediate to advanced
542 pages
13h 37m
English
Our final playback feature will be volume control. To allow us to control the playback level, QMediaPlayer has a volume parameter that accepts values from 0 (muted) to 100 (full volume).
We'll simply add another slider widget to control the volume, as follows:
self.volume = qtw.QSlider( minimum=0, maximum=100, sliderPosition=75, orientation=qtc.Qt.Horizontal, sliderMoved=self.player.setVolume ) self.layout().addWidget(self.volume, 2, 1)
After setting the minimum and maximum values accordingly, we just need to connect sliderMoved to the media player's setVolume() slot. That's all there is to it!
For smoother volume control, the Qt documentation recommends converting the slider's linear scale to a logarithmic scale. We ...
Read now
Unlock full access