Изменение размера изображения в зависимости от размера QFrame

Как отобразить разный размер картинки? Вот когда меню выдвинуто, пусть отображается значок апекса, а когда задвинуто, пусть отображается такая же картинка, но в уменьшенном формате.

введите сюда описание изображения

введите сюда описание изображения

Apex.py

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from PyQt5 import QtCore, QtGui, QtWidgets    
from PyQt5.QtGui import QColor, QIcon 
from PyQt5.uic import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        self.menuvisible = 0
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1209, 747)
        MainWindow.setStyleSheet("")
        MainWindow.setAnimated(True)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setStyleSheet("background-color: rgb(34, 31, 46);")
        self.centralwidget.setObjectName("centralwidget")
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setGeometry(QtCore.QRect(0, 160, 161, 591))
        self.frame.setStyleSheet("background-color: rgb(46, 43, 63);")
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.weapon = QtWidgets.QPushButton(self.frame)
        self.weapon.setGeometry(QtCore.QRect(40, 100, 121, 41))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.weapon.sizePolicy().hasHeightForWidth())
        self.weapon.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Copperplate Gothic Bold")
        font.setPointSize(14)
        font.setBold(False)
        font.setWeight(50)
        self.weapon.setFont(font)
        self.weapon.setStyleSheet("QPushButton {\n"
"    ;\n"
"    color: rgb(78, 75, 94);      \n"
"    background-color: rgba(255, 255, 255, 0);\n"
"    padding: 5px;\n"
"    }\n"
"\n"
"QPushButton:hover {\n"
"   \n"
"    \n"
"    \n"
"    color: rgb(168, 168, 168);\n"
"    }\n"
"\n"
"QPushButton:pressed {\n"
"    border-style: inset;\n"
"   \n"
"    \n"
"    color: rgb(214, 214, 214);\n"
"    }")
        self.weapon.setInputMethodHints(QtCore.Qt.ImhNone)
        self.weapon.setAutoExclusive(False)
        self.weapon.setObjectName("weapon")
        self.spravka = QtWidgets.QPushButton(self.frame)
        self.spravka.setGeometry(QtCore.QRect(40, 540, 111, 41))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.spravka.sizePolicy().hasHeightForWidth())
        self.spravka.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Copperplate Gothic Bold")
        font.setPointSize(12)
        font.setBold(False)
        font.setWeight(50)
        self.spravka.setFont(font)
        self.spravka.setStyleSheet("QPushButton {\n"
"    ;\n"
"    \n"
"    color: rgb(78, 75, 94);\n"
"    background-color: rgba(255, 255, 255, 0);\n"
"    padding: 5px;\n"
"\n"
"    }\n"
"QPushButton:hover {\n"
"   \n"
"    \n"
"    color: rgb(168, 168, 168);\n"
"    }\n"
"\n"
"QPushButton:pressed {\n"
"    border-style: inset;\n"
"   \n"
"    color: rgb(214, 214, 214);\n"
"    }")
        self.spravka.setInputMethodHints(QtCore.Qt.ImhNone)
        self.spravka.setAutoExclusive(False)
        self.spravka.setObjectName("spravka")
        self.label_10 = QtWidgets.QLabel(self.frame)
        self.label_10.setGeometry(QtCore.QRect(-20, 540, 61, 41))
        self.label_10.setText("")
        self.label_10.setPixmap(QtGui.QPixmap("Nikita_Pfeyfer4.png"))
        self.label_10.setObjectName("label_10")
        self.label_9 = QtWidgets.QLabel(self.frame)
        self.label_9.setGeometry(QtCore.QRect(-30, 100, 81, 41))
        self.label_9.setText("")
        self.label_9.setPixmap(QtGui.QPixmap("Nikita_Pfeyfer2.png"))
        self.label_9.setObjectName("label_9")
        self.menu = QtWidgets.QPushButton(self.frame)
        self.menu.clicked.connect(self.showmenu) 
        self.menu.setGeometry(QtCore.QRect(10, 20, 51, 51))

        self.menu.setStyleSheet("background-image: url(:/menu/Изображения/back.png);\n"
"border: 1px solid rgba(255, 255, 255, 0);\n"
"")
        self.menu.setText("")
        self.menu.setObjectName("menu")
        self.frame_2 = QtWidgets.QFrame(self.centralwidget)
        self.frame_2.setGeometry(QtCore.QRect(0, 0, 1211, 21))
        self.frame_2.setStyleSheet("background-color: rgb(46, 43, 63);")
        self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_2.setObjectName("frame_2")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(610, 90, 231, 41))
        font = QtGui.QFont()
        font.setFamily("Copperplate Gothic Bold")
        font.setPointSize(28)
        self.label.setFont(font)
        self.label.setStyleSheet("color: rgb(253, 253, 253);")
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setGeometry(QtCore.QRect(600, 130, 241, 2))
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.frame_3 = QtWidgets.QFrame(self.centralwidget)
        self.frame_3.setGeometry(QtCore.QRect(260, 180, 261, 161))
        self.frame_3.setStyleSheet("background-color: rgb(46, 43, 63);\n"
"border: 2px solid #2e2b3f;\n"
"border-radius: 10")
        self.frame_3.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_3.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_3.setObjectName("frame_3")
        self.label_3 = QtWidgets.QLabel(self.frame_3)
        self.label_3.setGeometry(QtCore.QRect(70, 0, 121, 41))
        font = QtGui.QFont()
        font.setFamily("Bahnschrift SemiBold")
        font.setPointSize(22)
        font.setBold(True)
        font.setWeight(75)
        self.label_3.setFont(font)
        self.label_3.setStyleSheet("color: rgb(194, 194, 194);")
        self.label_3.setAlignment(QtCore.Qt.AlignCenter)
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(self.frame_3)
        self.label_4.setGeometry(QtCore.QRect(70, 60, 121, 61))
        font = QtGui.QFont()
        font.setFamily("Bahnschrift SemiBold")
        font.setPointSize(22)
        font.setBold(True)
        font.setWeight(75)
        self.label_4.setFont(font)
        self.label_4.setStyleSheet("")
        self.label_4.setAlignment(QtCore.Qt.AlignCenter)
        self.label_4.setObjectName("label_4")
        self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
        self.textBrowser.setGeometry(QtCore.QRect(570, 170, 256, 351))
        self.textBrowser.setStyleSheet("background-color: rgb(46, 43, 63);\n"
"border: 2px solid #2e2b3f;\n"
"border-radius: 10")
        self.textBrowser.setObjectName("textBrowser")
        self.frame_4 = QtWidgets.QFrame(self.centralwidget)
        self.frame_4.setGeometry(QtCore.QRect(560, 720, 201, 20))
        self.frame_4.setStyleSheet("background-color: rgb(46, 43, 63);\n"
"border: 2px solid #2e2b3f;\n"
"border-radius: 10")
        self.frame_4.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_4.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_4.setObjectName("frame_4")
        self.label_5 = QtWidgets.QLabel(self.frame_4)
        self.label_5.setGeometry(QtCore.QRect(50, -2, 101, 21))
        font = QtGui.QFont()
        font.setFamily("Bahnschrift SemiBold SemiConden")
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.label_5.setFont(font)
        self.label_5.setAlignment(QtCore.Qt.AlignCenter)
        self.label_5.setObjectName("label_5")
        self.textBrowser_2 = QtWidgets.QTextBrowser(self.centralwidget)
        self.textBrowser_2.setGeometry(QtCore.QRect(260, 360, 261, 161))
        self.textBrowser_2.setStyleSheet("background-color: rgb(46, 43, 63);\n"
"border: 2px solid #2e2b3f;\n"
"border-radius: 10")
        self.textBrowser_2.setObjectName("textBrowser_2")
        self.line_2 = QtWidgets.QFrame(self.centralwidget)
        self.line_2.setGeometry(QtCore.QRect(309, 391, 161, 2))
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.line_3 = QtWidgets.QFrame(self.centralwidget)
        self.line_3.setGeometry(QtCore.QRect(331, 219, 121, 2))
        self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_3.setObjectName("line_3")
        self.textBrowser_3 = QtWidgets.QTextBrowser(self.centralwidget)
        self.textBrowser_3.setGeometry(QtCore.QRect(870, 170, 256, 351))
        self.textBrowser_3.setStyleSheet("background-color: rgb(46, 43, 63);\n"
"border: 2px solid #6c6c00;\n"
"border-radius: 10")
        self.textBrowser_3.setObjectName("textBrowser_3")
        self.line_4 = QtWidgets.QFrame(self.centralwidget)
        self.line_4.setGeometry(QtCore.QRect(897, 200, 201, 2))
        self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_4.setObjectName("line_4")
        self.frame_5 = QtWidgets.QFrame(self.centralwidget)
        self.frame_5.setGeometry(QtCore.QRect(0, -1, 161, 170))
        self.frame_5.setStyleSheet("background-color: rgb(46, 43, 63);")
        self.frame_5.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_5.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_5.setObjectName("frame_5")
        self.mainmenu = QtWidgets.QPushButton(self.frame_5)
        self.mainmenu.setGeometry(QtCore.QRect(0, 0, 161, 161))
        self.mainmenu.setStyleSheet("background-image: url(:/Fone/Изображения/_Logotip_Proz3.png); \n"
"border: 1px solid rgba(255, 255, 255, 0);\n"
"")
        self.mainmenu.setText("")
        self.mainmenu.setObjectName("mainmenu")
        self.frame_2.raise_()
        self.frame.raise_()
        self.label.raise_()
        self.line.raise_()
        self.frame_3.raise_()
        self.textBrowser.raise_()
        self.frame_4.raise_()
        self.textBrowser_2.raise_()
        self.line_2.raise_()
        self.line_3.raise_()
        self.textBrowser_3.raise_()
        self.line_4.raise_()
        self.frame_5.raise_()
        MainWindow.setCentralWidget(self.centralwidget)
        self.action = QtWidgets.QAction(MainWindow)
        self.action.setObjectName("action")

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.weapon.setText(_translate("MainWindow", "Weapons"))
        self.spravka.setText(_translate("MainWindow", "Reference"))
        self.label.setText(_translate("MainWindow", "Main Menu"))
        self.label_3.setText(_translate("MainWindow", "Версия"))
        self.label_4.setText(_translate("MainWindow", "1.0 BETA"))
        self.textBrowser.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt; font-weight:600; color:#c2c2c2;\">ApexHelper</span></p>\n"
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt; font-weight:600;\"><br /></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt;\">Эта программа предназначена для того, чтобы помочь новичкам или опытным игрокам более лучше освоить игру</span></p>\n"
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt;\"><br /></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt; font-weight:600; color:#c2c2c2;\">_Apex Legends_</span></p>\n"
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt; font-weight:600; color:#c2c2c2;\"><br /></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt;\">Тут ты найдёшь подробное описание каждого оружия,</span><span style=\" font-size:12pt; text-decoration: underline;\"> </span><span style=\" font-size:12pt;\">обвеса и прочих вещей.</span></p>\n"
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt;\"><br /></p>\n"
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt;\"><br /></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt; font-style:italic; color:#c2c2c2;\">С уважением, Разработчик </span><span style=\" font-size:12pt; font-weight:600; font-style:italic; color:#c2c2c2;\">ApexHelper</span><span style=\" font-size:12pt; color:#c2c2c2;\">.</span></p>\n"
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt;\"><br /></p></body></html>"))
        self.label_5.setText(_translate("MainWindow", "Всё для вас!"))
        self.textBrowser_2.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt; font-weight:600; color:#c2c2c2;\">Информация</span></p>\n"
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;\"><br /></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:12pt;\">Программа находится в разработке, поэтому, пока что присудствует не вся информация </span></p></body></html>"))
        self.textBrowser_3.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt; color:#c2c2c2;\">Кому принадлежит</span></p>\n"
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt;\"><br /></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt;\">Все данные, изображения и прочее из программы, принадлежат компании</span></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt;\"> </span></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:14pt; font-weight:600; color:#6f6f0a;\">Respawn Entertainment</span></p>\n"
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt; font-weight:600;\"><br /></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:14pt;\">Никому более.</span></p>\n"
"<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;\"><br /></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:14pt;\">Их материал был повзаимствован для помощи игрокам.</span></p></body></html>"))
        self.action.setText(_translate("MainWindow", "справка"))

    def showmenu(self):
        self.anim = QPropertyAnimation(self.frame, b'size')
        self.anim.setDuration(250)
        if self.menuvisible==0:
            self.anim.setStartValue(QSize(50,751))
            self.anim.setEndValue(QSize(161, 751))
            self.menuvisible = 1
        else:
            self.anim.setStartValue(QSize(161,751))
            self.anim.setEndValue(QSize(50, 751))
            self.menuvisible = 0
            #self.anim.finished.connect(self.hidemenu)
        self.frame.show()
        self.anim.start()

import ApexFone
import menu

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

Ответы (2 шт):

Автор решения: Александр Рассказчиков

Создайте дополнительный ассет - картинка с необходимым вам размером, после чего, когда выполняется функция "сворачивания" меню, программно меняйте background-image через изменение css-свойств (stylesheet) объекта.

Например, так:

class MainWindow():
...

    def wrap_menu(self, *args):
    ...
    
    self.menuLogo.setStylesheet("background-image: url(small-logo.png);")
    ...
→ Ссылка
Автор решения: S. Nick

Я покажу вам возможное решение того, что вы хотите сделать.

Установите свои изображения и запустите мой пример. Автоматический выполнится некоторые анимации. Затем нажмите на кнопки в произвольном порядке.

Затем попробуйте изменять размеры окна. Попробуйте также изменять размеры окна вашего приложения и почувствуйте разницу.

Я вам уже писал, что без менеджеров компоновки вы далеко не уедите. Чем быстрее вы освоите данную тему, тем лучше будет для вас.

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.Qt import *


class ImageLabel(QtWidgets.QGraphicsView):
    def __init__(self, *args, **kwargs):
        super(ImageLabel, self).__init__(*args, **kwargs)
        self.setScene(QtWidgets.QGraphicsScene())
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) 
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

    def setImage(self, filename):
        self.setPixmap(QtGui.QPixmap(filename))

    def setPixmap(self, pixmap):
        item = QtWidgets.QGraphicsPixmapItem(pixmap)
        item.setTransformationMode(QtCore.Qt.SmoothTransformation)
        self.scene().addItem(item)

    def resizeEvent(self, event):
        r = self.scene().itemsBoundingRect()
        self.fitInView(r, QtCore.Qt.KeepAspectRatio)
        super(ImageLabel, self).resizeEvent(event)
        

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(640, 480)
        self.horizontalLayout = QtWidgets.QHBoxLayout(Form)
        self.horizontalLayout.setObjectName("horizontalLayout")
        
        self.listWidget = QtWidgets.QListWidget(Form)
        self.listWidget.setObjectName("listWidget")
        self.listWidget.setStyleSheet(
            "#listWidget {background-color: #753422;}")
        self.horizontalLayout.addWidget(self.listWidget)
        
        self.frame = QtWidgets.QFrame(Form)
        self.frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
        self.frame.setObjectName("frame")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.listWidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.image = ImageLabel()
        self.image.setObjectName("image")
        self.verticalLayout.addWidget(self.image)
        self.pushButton_2 = QtWidgets.QPushButton(self.frame)
        self.pushButton_2.setObjectName("pushButton_2")
        self.verticalLayout.addWidget(self.pushButton_2)
        self.pushButton_3 = QtWidgets.QPushButton(self.frame)
        self.pushButton_3.setObjectName("pushButton_3")
        self.verticalLayout.addWidget(self.pushButton_3)
        spacerItem = QtWidgets.QSpacerItem(
            20, 40, 
            QtWidgets.QSizePolicy.Policy.Minimum, 
            QtWidgets.QSizePolicy.Policy.Expanding
        )
        self.verticalLayout.addItem(spacerItem)        

        self.listWidget_2 = QtWidgets.QListWidget(Form)
        self.listWidget_2.setObjectName("listWidget_2")
        self.listWidget_2.setStyleSheet("background-color: #D79771;")
        self.horizontalLayout.addWidget(self.listWidget_2)
        self.frame_2 = QtWidgets.QFrame(Form)
        self.frame_2.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
        self.frame_2.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
        self.frame_2.setObjectName("frame_2")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.listWidget_2)
        self.verticalLayout_2.setObjectName("verticalLayout_2")        
        self.image_2 = ImageLabel()
        self.image_2.setObjectName("image_2")
        self.verticalLayout_2.addWidget(self.image_2)        
        
        self.listWidget_3 = QtWidgets.QListWidget(Form)
        self.listWidget_3.setObjectName("listWidget_3")
        self.listWidget_3.setStyleSheet("background-color: #B05B3B;")
        self.horizontalLayout.addWidget(self.listWidget_3)
        self.frame_3 = QtWidgets.QFrame(Form)
        self.frame_3.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
        self.frame_3.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
        self.frame_3.setObjectName("frame_3")
        self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.listWidget_3)
        self.verticalLayout_3.setObjectName("verticalLayout_3")        
        self.image_3 = ImageLabel()
        self.image_3.setObjectName("image_3")
        self.verticalLayout_3.addWidget(self.image_3)
        
        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.pushButton_2.setText(_translate("Form", "Нажми меня"))
        self.pushButton_3.setText(_translate("Form", "и меня нажми"))
        

class DemoImageLabel(QWidget, Ui_Form):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        
        self.image.setImage("boy.jpg")        # установите свое изображение !!!
        self.image.setMaximumHeight(200)
        self.image_2.setImage("lena.jpg")     # установите свое изображение !!!
        self.image_3.setImage("fg.png")       # установите свое изображение !!!
        
        self.pushButton_2.clicked.connect(self.animate_listwidget2)
        self.pushButton_3.clicked.connect(self.animate_listwidget3)

        self.animation1 = self.build_animation(self.listWidget_2)
        self.animation2 = self.build_animation(self.listWidget_3)
        
        QtCore.QTimer.singleShot(2000, self.animate_listwidget2)        
        QtCore.QTimer.singleShot(3000, self.animate_listwidget3)
        QtCore.QTimer.singleShot(5000, self.animate_listwidget2)        
        QtCore.QTimer.singleShot(6000, self.animate_listwidget3)

    def build_animation(self, listwidget):
        animation = QPropertyAnimation(listwidget, b"maximumWidth")
        animation.setDuration(800)
        animation.setEasingCurve(QEasingCurve.Type.Linear)
        return animation

    def start_animation(self, animation):
        width = animation.targetObject().width()
        animation.stop()
        animation.setStartValue(width)
        animation.setEndValue(0 if width != 0 else 350)
        animation.start()

    def animate_listwidget2(self):
        self.start_animation(self.animation1)

    def animate_listwidget3(self):
        self.start_animation(self.animation2)


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    w = DemoImageLabel()
    w.resize(800, 600)
    w.show()
    sys.exit(app.exec())

введите сюда описание изображения

введите сюда описание изображения

введите сюда описание изображения

введите сюда описание изображения

→ Ссылка