Skip to content

Instantly share code, notes, and snippets.

@dequegorg
Created August 19, 2011 07:33
Show Gist options
  • Save dequegorg/1156262 to your computer and use it in GitHub Desktop.
Save dequegorg/1156262 to your computer and use it in GitHub Desktop.
Qt Child Widget Slide Animation
#!/usr/bin/env python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="benjamin"
__date__ ="$Aug 19, 2011 8:23:20 AM$"
import sys
from PyQt4 import QtGui, QtCore
application = QtGui.QApplication(sys.argv)
class Dashboard(QtGui.QWidget):
""" Dashboard to slide up and down on request. """
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
self.pix = QtGui.QPixmap("futurame.jpg")
self.label = QtGui.QLabel(self)
self.label.setPixmap(self.pix)
self.layout = QtGui.QHBoxLayout(self)
self.layout.addWidget(self.label)
self.layout.setContentsMargins(1,1,1,1)
self.layout.setSizeConstraint(QtGui.QLayout.SetNoConstraint)
self.setLayout(self.layout)
class MainWindow(QtGui.QWidget):
""" Main Window hosting button and dashboard"""
def __init__(self):
QtGui.QWidget.__init__(self)
self.dashboard = Dashboard(self)
self.toggleButton = QtGui.QPushButton(QtCore.QString("Open Dashboard"))
self.toggleButton.setMinimumHeight(27)
self.layout = QtGui.QVBoxLayout(self)
self.layout.addWidget(self.dashboard)
self.layout.addWidget(self.toggleButton)
self.layout.setContentsMargins(1,1,1,1)
self.layout.setSizeConstraint(QtGui.QLayout.SetNoConstraint)
self.setLayout(self.layout)
self.connect(self.toggleButton, QtCore.SIGNAL('clicked()'), self.toggle)
def toggle(self):
self.hideAnimation = QtCore.QPropertyAnimation(self.dashboard, "geometry")
self.parentHideAnimation = QtCore.QPropertyAnimation(self, "geometry")
self.hideAnimation.setDuration(300)
self.parentHideAnimation.setDuration(300)
self.dashboard.startGeometry = QtCore.QRect(self.dashboard.geometry())
self.startGeometry = QtCore.QRect(self.geometry())
self.dashboard.endGeometry = QtCore.QRect(0,self.dashboard.geometry().height(),self.dashboard.geometry().width(), 0)
self.endGeometry = QtCore.QRect(self.geometry().x(),
self.geometry().y() + self.dashboard.geometry().height(),
self.dashboard.width(),
self.toggleButton.geometry().height())
self.hideAnimation.setStartValue(self.dashboard.startGeometry)
self.parentHideAnimation.setStartValue(self.startGeometry)
self.hideAnimation.setEndValue(self.dashboard.endGeometry)
self.parentHideAnimation.setEndValue(self.endGeometry)
self.hideAnimation.start()
self.parentHideAnimation.start()
if __name__ == "__main__":
main = MainWindow()
main.show()
sys.exit(application.exec_())
@sanfx
Copy link

sanfx commented Nov 17, 2013

not working exactly as expected in OSx..

@Cescfangs
Copy link

it worked, thanks for the code
[Mac OS X 10.10.5]

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