Увеличение и уменьшение кнопки, анимация
Для кнопки self.pushButtonProfil
e я создал анимацию на увеличение при нажатии, а при втором нажатии она должна вернуться.
Обратный возврат height
кнопки не работает.
Код написан на PyQt6:
class AboutTheProgram(QDialog, Ui_AboutTheProgram):
def __init__(self):
super().__init__()
self.nameUsers = None
self.oldPos = None
self.ui = None
self.logo_text = None
self.abouttheprogram = Ui_AboutTheProgram
self.setupUi(self)
self.importmainclass = MainWindows
self.importregclass = Refistration
self.nameUsers = os.getlogin()
if os.path.isfile(f'/Users/{self.nameUsers}\Downloads/soft.txt'):
os.remove(f'/Users/{self.nameUsers}\Downloads/soft.txt')
print("success")
else:
print("File doesn't exists!")
#Импорт основных методов передвижение окна windows и убарать windows элементы из виджета.
self.importmainclass.RemoveWindowsMenu(self)
self.pushClose.clicked.connect(self.importmainclass.CloseWindow)#кнопка завершение программы
self.pushCollapse.clicked.connect(self.showMinimized)#Сворачивание окна
self.pushExit.clicked.connect(self.PushBack)#кнопка для выхода с аккаунта
self.pushDownload.clicked.connect(self.download)
#Работа с кнопкой профиль
self.layout = QVBoxLayout()
self.layout.addWidget(self.pushButtonProfile)
self.setLayout(self.layout)
self.pushButtonProfile.clicked.connect(self.on_button_clicked)
self.animation = None
self.is_expanded = False
def on_button_clicked(self):
if not self.animation or self.animation.state() == QAbstractAnimation.State.Stopped:
if not self.is_expanded:
self.animation = QPropertyAnimation(self.pushButtonProfile, b"minimumSize")
self.animation.setDuration(300)
self.animation.setStartValue(QSize(self.pushButtonProfile.width(), 31))
self.animation.setEndValue(QSize(self.pushButtonProfile.width(), 111))
self.animation.start()
self.is_expanded = True
else:
self.animation = QPropertyAnimation(self.pushButtonProfile, b"minimumSize")
self.animation.setDuration(600)
self.animation.setStartValue(QSize(self.pushButtonProfile.width(), 111))
self.animation.setEndValue(QSize(self.pushButtonProfile.width(), 31))
self.animation.start()
self.is_expanded = False
Источник: Stack Overflow на русском