Skip to content

Instantly share code, notes, and snippets.

@itarozzi
Forked from CoutinhoElias/main.py
Last active January 28, 2021 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save itarozzi/c757a46f031e81e6d4d269202864f9f8 to your computer and use it in GitHub Desktop.
Save itarozzi/c757a46f031e81e6d4d269202864f9f8 to your computer and use it in GitHub Desktop.
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

Thank you!

@itarozzi
Copy link
Author

itarozzi commented Jan 27, 2021 via email

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