Как сделать выдвижное меню?
где-то я видел, что из Label, можно сделать выдвигающуюся меню, как мне сделать в левой части выдвигающуюся менюшку?
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Apex.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1209, 748)
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, 0, 161, 751))
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, 197, 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, 690, 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, 690, 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, 200, 81, 41))
self.label_9.setText("")
self.label_9.setPixmap(QtGui.QPixmap("Nikita_Pfeyfer2.png"))
self.label_9.setObjectName("label_9")
self.label_2 = QtWidgets.QLabel(self.frame)
self.label_2.setGeometry(QtCore.QRect(0, 20, 141, 121))
self.label_2.setText("")
self.label_2.setPixmap(QtGui.QPixmap("Изображения/logo.png"))
self.label_2.setObjectName("label_2")
self.frame_2 = QtWidgets.QFrame(self.centralwidget)
self.frame_2.setGeometry(QtCore.QRect(160, 0, 1051, 71))
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")
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", "справка"))
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 шт):
Автор решения: Sergey Tatarincev
→ Ссылка
Например так
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.menuvisible = 0
def hidemenu(self):
self.menu.hide()
def showmenu(self):
self.anim = QPropertyAnimation(self.menu, b'size')
self.anim.setDuration(500)
if self.menuvisible==0:
self.anim.setStartValue(QSize(0,0))
self.anim.setEndValue(QSize(100, 100))
self.menuvisible = 1
else:
self.anim.setStartValue(QSize(100,100))
self.anim.setEndValue(QSize(0, 0))
self.menuvisible = 0
self.anim.finished.connect(self.hidemenu)
self.menu.show()
self.anim.start()
def initUI(self):
button = QPushButton("menu")
button.setObjectName("button")
button.clicked.connect(self.showmenu)
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
button.setSizePolicy(sizePolicy)
vbox = QVBoxLayout()
vbox.addWidget(button)
vbox.addStretch(1)
frame = QFrame()
frame.setFrameShape(QFrame.StyledPanel)
frame.setStyleSheet("background-color: red;")
frame.setLineWidth(1)
self.menu = QFrame()
self.menu.setFrameShape(QFrame.StyledPanel)
self.menu.setStyleSheet("background-color: green;")
self.menu.setLineWidth(1)
self.menu.setMinimumWidth(0);
self.menu.hide()
menusizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
menusizePolicy.setHorizontalStretch(0)
menusizePolicy.setVerticalStretch(0)
self.menu.setSizePolicy(menusizePolicy)
button1 = QPushButton("button1")
button2 = QPushButton("button2")
button3 = QPushButton("button3")
mvbox = QVBoxLayout()
mvbox.addWidget(button1)
mvbox.addWidget(button2)
mvbox.addWidget(button3)
mvbox.addStretch(1)
self.menu.setLayout(mvbox)
hbox = QHBoxLayout()
hbox.addLayout(vbox)
hbox.addWidget(self.menu)
hbox.addWidget(frame)
self.setLayout(hbox)
self.setGeometry(400, 400, 400, 400)
self.setWindowTitle('Buttons')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
Автор решения: S. Nick
→ Ссылка
Я увидел вашу задачу так:
import sys
import random
from PyQt5 import QtCore, QtGui, QtWidgets
class CollapsibleBox(QtWidgets.QWidget):
def __init__(self, i, title="", parent=None):
super(CollapsibleBox, self).__init__(parent)
self.toggle_button = QtWidgets.QToolButton(
text=title, checkable=True, checked=False,
objectName=f'button{i}'
)
self.toggle_button.setFixedSize(75, 75)
self.toggle_button.setToolButtonStyle(
QtCore.Qt.ToolButtonTextBesideIcon )
self.toggle_button.setArrowType(QtCore.Qt.RightArrow)
self.toggle_button.pressed.connect(self.on_pressed)
self.toggle_animation = QtCore.QParallelAnimationGroup(self)
self.content_area = QtWidgets.QScrollArea(
maximumHeight=0, minimumHeight=0
)
self.content_area.setSizePolicy(
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed
)
self.content_area.setFrameShape(QtWidgets.QFrame.NoFrame)
lay = QtWidgets.QVBoxLayout(self)
lay.setSpacing(0)
lay.setContentsMargins(0, 0, 0, 0)
lay.addWidget(self.toggle_button, alignment=QtCore.Qt.AlignCenter)
lay.addWidget(self.content_area)
self.toggle_animation.addAnimation(
QtCore.QPropertyAnimation(self, b"minimumHeight")
)
self.toggle_animation.addAnimation(
QtCore.QPropertyAnimation(self, b"maximumHeight")
)
self.toggle_animation.addAnimation(
QtCore.QPropertyAnimation(self.content_area, b"maximumHeight")
)
@QtCore.pyqtSlot()
def on_pressed(self):
checked = self.toggle_button.isChecked()
self.toggle_button.setArrowType(
QtCore.Qt.DownArrow if not checked else QtCore.Qt.RightArrow
)
self.toggle_animation.setDirection(
QtCore.QAbstractAnimation.Forward
if not checked
else QtCore.QAbstractAnimation.Backward
)
self.toggle_animation.start()
def setContentLayout(self, layout):
lay = self.content_area.layout()
del lay
self.content_area.setLayout(layout)
collapsed_height = (
self.sizeHint().height() - self.content_area.maximumHeight()
)
content_height = layout.sizeHint().height()
for i in range(self.toggle_animation.animationCount()):
animation = self.toggle_animation.animationAt(i)
animation.setDuration(500)
animation.setStartValue(collapsed_height)
animation.setEndValue(collapsed_height + content_height)
content_animation = self.toggle_animation.animationAt(
self.toggle_animation.animationCount() - 1
)
content_animation.setDuration(500)
content_animation.setStartValue(0)
content_animation.setEndValue(content_height)
class LeftWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
centralWidget = QtWidgets.QWidget()
self.setCentralWidget(centralWidget)
vlay = QtWidgets.QVBoxLayout(centralWidget)
for i in range(2):
box = CollapsibleBox(i, "")
vlay.addWidget(box)
lay = QtWidgets.QVBoxLayout()
lay.setSpacing(0)
lay.setContentsMargins(0, 0, 0, 0)
for j in range(2):
label = QtWidgets.QLabel("Label {}-{}".format(i, j))
color = QtGui.QColor(*[random.randint(0, 255) for _ in range(3)])
label.setStyleSheet(
"background-color: {}; color : white;".format(color.name())
)
label.setAlignment(QtCore.Qt.AlignCenter)
label.setMaximumWidth(150)
label.setMinimumHeight(25)
textButton = "Button {}-{}".format(i, j)
pushButton = QtWidgets.QPushButton(textButton,
clicked=lambda _, t=textButton: print(t))
pushButton.setMaximumWidth(150)
pushButton.setMinimumHeight(25)
lay.addWidget(pushButton)
lay.addWidget(label)
box.setContentLayout(lay)
vlay.addStretch()
self.label_2 = QtWidgets.QLabel()
self.label_2.setPixmap(QtGui.QPixmap("ball.png"))
vlay.addWidget(self.label_2)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
centralWidget = QtWidgets.QWidget()
self.setCentralWidget(centralWidget)
layout = QtWidgets.QGridLayout(centralWidget)
self.leftWindow = LeftWindow()
self.leftWindow.setMaximumWidth(150)
self.textBrowser_2 = QtWidgets.QTextBrowser()
layout.addWidget(self.leftWindow, 0, 0)
layout.addWidget(self.textBrowser_2, 0, 1)
layout.setColumnStretch(0, 0)
layout.setColumnStretch(1, 1)
qss = '''
#button0 {
border: none;
margin: 0px;
padding: 0px;
border-image: url(Ok.png);
}
#button0:checked {
border-image: url(lena-2.png);
}
'''
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
app.setStyleSheet(qss)
w = MainWindow()
w.resize(600, 500)
w.show()
sys.exit(app.exec_())


