QT realizes volume control in player

Source: Internet
Author: User

In the video player, it is necessary and simple to implement the drag control bar to adjust the volume. Here is a specific word.

First, open the. ui file, drag a slider in the right place, like this, and look at the lower right corner.


For the sake of the image, you can place a small horn on the left to show that it is used to adjust the volume.

Then, set the signal with the slot. The method is to select Slider, and then click the signal and slot in the upper left corner.


Next, select Slider, pointing outwards, a window pops up, and a valuechanged () is selected to indicate the trigger when the progress value changes. The remaining several representations are: sliderpressed () triggered when the user presses, slidermoved () triggered when the user drags the slider, and sliderreleased () when the user releases the slider.

When we select ValueChanged (), we can edit the slot function on the right side and add a changevolume () function.

Then add some statements in the code. (Manually add a way, if the right click to go to the slot function will be easier)

First, in the. h header file, declare a slot function. See line 40th


Then, add the Connect join function in the. cpp file.

Conncect (Ui.horizontalslider,signal (qslider::valuechanged (int)), This,slot (Changevolume ()));

The first parameter represents object, which is the name of my volume control bar. The second parameter represents the signal, and the third is the accepted object, typically this, and the last is the slot function.

Finally, the slot function is edited.

Where the player is a Qmediaplayer object, call the SetVolume () method directly. The argument is the value of the slider.

In doing this part of the function, I have always found that the volume can not adjust, regardless of the set which signal, sliderpressed (), slidermoved () or valuechanged () signal, drag the slider, the volume does not change. One evening plus one morning, no problem found. Later, after the. ui file was closed and saved, the rerun found no problem, is the signal and slot function can not be updated dynamically under VS2013. But my playback progress bar didn't run into this problem when I was writing it. Welcome also to meet the volume can not be tuned to communicate with friends.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.