A
A
Anire19852022-03-12 08:49:42
Python
Anire1985, 2022-03-12 08:49:42

sound hover button. How to play a sound when hovering over a button?

I am making an application. I want to add a sound effect when hovering over a button.
Found a suitable inheritance code from the class. And it works well for me. How to add it to certain buttons?
pushButton_1
pushButton_3
pushButton_5

Form, Window = uic.loadUiType("HL_main.ui")
app = QApplication([])
window = Window()
form = Form()
form.setupUi(window)
window.setWindowFlags(QtCore.Qt.FramelessWindowHint)

class HoverButton(QPushButton):
    def __init__(self, *args, **kwargs):
        super(HoverButton, self).__init__(*args, **kwargs)


    def enterEvent(self, e):
        pygame.mixer.music.load('./res/musik/btn_hover.mp3')
        pygame.mixer.music.play(0)
        print("OK")

    def leaveEvent(self, e):
        pass

I created these buttons in the designer beforehand. And when I write the code
pushButton_12 = HoverButton(window)
, a new button is created. I need additional functions to appear in the one I created earlier.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anire1985, 2022-03-14
@Anire1985

Found an answer on stackoverflow for a query
Perform actions on hover over QPushButton PyQt5

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question