Skip to content

Instantly share code, notes, and snippets.

@itarozzi
Forked from CoutinhoElias/main.py
Last active Jan 28, 2021
Embed
What would you like to do?
Frame
from PySide2.QtWidgets import (QApplication, QWidget, QPushButton, QMainWindow, QSizePolicy,
QFrame, QLabel, QLineEdit, QHBoxLayout, QVBoxLayout)
from PySide2.QtGui import QIcon, QFont
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtCore import (QCoreApplication, QPropertyAnimation, QDate, QDateTime, QMetaObject, QObject, QPoint, QRect, QSize, QTime, QUrl, Qt, QEvent)
import sys
class MyWidget(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Conversor de arquivos")
self.setGeometry(300, 100, 900, 600) # x, y, w, h -> esquerda, topo, largura, altura
self.setMinimumHeight(500)
self.setMinimumWidth(700)
self.vbox_main = QVBoxLayout()
self.hbox_main = QHBoxLayout()
self.hbox_main.setContentsMargins(0, 0, 0, 0)
self.hbox_main.stretch(1)
self.vbox_menu_left = QVBoxLayout()
self.vbox_menu_left.setSpacing(5)
self.button_toggle = QPushButton("TOGGLE")
self.button_toggle.setMaximumSize(100,40)
self.button_toggle.clicked.connect(self.toggle)
self.button1 = QPushButton("BTN1")
self.button2 = QPushButton("BTN2")
self.button3 = QPushButton("BTN3")
self.frame_left_menu = QFrame()
self.frame_left_menu.setStyleSheet('background-color: green')
self.frame_left_menu.setMaximumSize(QSize(70, 16777215))
self.frame = QFrame()
self.frame.setStyleSheet('background-color: yellow')
self.frame.setMinimumWidth(16777215)
# Add objects to layouts
self.vbox_menu_left.addWidget(self.button1)
self.vbox_menu_left.addWidget(self.button2)
self.vbox_menu_left.addWidget(self.button3)
self.frame_left_menu.setLayout(self.vbox_menu_left)
self.hbox_main.addWidget(self.frame_left_menu)
self.hbox_main.addWidget(self.frame)
self.vbox_main.addWidget(self.button_toggle)
self.vbox_main.addLayout(self.hbox_main)
self.setLayout(self.vbox_main)
def toggle(self):
width = self.frame_left_menu.width()
if (width == 70):
widthExtended = 200
else:
widthExtended = 70
# use simple assignement
#self.frame_left_menu.setMinimumWidth(widthExtended)
# or use fancy ANIMATION
self.animation = QPropertyAnimation(self.frame_left_menu, b"minimumWidth")
self.animation.setDuration(400)
self.animation.setStartValue(width)
self.animation.setEndValue(widthExtended)
self.animation.setEasingCurve(QtCore.QEasingCurve.InOutQuart)
self.animation.start()
if __name__ == "__main__":
app = QtWidgets.QApplication([])
widget = MyWidget()
widget.resize(400, 300)
widget.show()
sys.exit(app.exec_())
@CoutinhoElias
Copy link

CoutinhoElias commented Jan 27, 2021

Thank you!

@itarozzi
Copy link
Author

itarozzi commented Jan 27, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment