Answer the question
In order to leave comments, you need to log in
How to assign additional parameters to an already created object?
I created a main.ui form in the designer that already has buttons
pushButton_1 pushButton_3 pushButton_5
and just import all the code into my application main.py
Now I need to add additional functionality to these buttons, namely the sound when hovering over the button.
Something like hover. How to implement it?
All my efforts boiled down to the fact that a new button was created, and parameters were not added to the one created in the designer.
from PyQt5.QtWidgets import QApplication, QPushButton
from PyQt5 import QtCore, QtWidgets, uic, QtGui
import pygame
from pygame import mixer
mixer.init() # звуковой движок
Form, Window = uic.loadUiType("HL_main_new.ui")
app = QApplication([])
window = Window()
form = Form()
form.setupUi(window)
window.setWindowFlags(QtCore.Qt.FramelessWindowHint)
class HoverButton(QPushButton):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# это тот самый параметр которы я хочу добавить.
def enterEvent(self, e):
pygame.mixer.music.load('./res/musik/btn_hover.mp3')
pygame.mixer.music.play(0)
def leaveEvent(self, e):
pass
form.pushButton_12 = HoverButton(window)
window.show()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question