Skip to content

Instantly share code, notes, and snippets.

@justinfx
Created September 29, 2012 04:34
Show Gist options
  • Save justinfx/3803172 to your computer and use it in GitHub Desktop.
Save justinfx/3803172 to your computer and use it in GitHub Desktop.
Dialog with an animated show event
from PyQt4 import QtCore, QtGui
class AnimatedDialog(QtGui.QDialog):
def __init__(self, parent=None):
super(AnimatedDialog, self).__init__(parent)
self.text = QtGui.QLineEdit(self)
self.text.move(20,20)
def showEvent(self, event):
size = self.size()
start_size = QtCore.QSize(size.width(), 0)
self.resize(start_size)
anim = QtCore.QPropertyAnimation(self, 'size', self)
anim.setStartValue(start_size)
anim.setEndValue(size)
anim.setDuration(700)
self.show()
anim.start()
event.accept()
if __name__ == "__main__":
app = QtGui.QApplication([])
win = AnimatedDialog()
win.resize(300,100)
win.show()
win.raise_()
app.exec_()
from PyQt4 import QtCore, QtGui
class AnimatedDialog(QtGui.QDialog):
def __init__(self, parent=None):
super(AnimatedDialog, self).__init__(parent)
self.text = QtGui.QLineEdit(self)
self.text.move(20,20)
self._shaker = QtCore.QPropertyAnimation(self, 'pos', self)
self._shaker.setDuration(300)
self.text.returnPressed.connect(self.shakey)
def showEvent(self, event):
size = self.size()
start_size = QtCore.QSize(size.width(), 0)
self.resize(start_size)
anim = QtCore.QPropertyAnimation(self, 'size', self)
anim.setStartValue(start_size)
anim.setEndValue(size)
anim.setDuration(100)
self.show()
anim.start()
event.accept()
def shakey(self):
pos = self.pos()
shaker = self._shaker
shaker.setStartValue(pos)
shaker.setEndValue(pos)
pos.setX(pos.x()+20)
shaker.setKeyValueAt(.2, pos)
shaker.setKeyValueAt(.6, pos)
pos.setX(pos.x()-40)
shaker.setKeyValueAt(.4, pos)
shaker.setKeyValueAt(.8, pos)
shaker.start()
if __name__ == "__main__":
app = QtGui.QApplication([])
win = AnimatedDialog()
win.resize(300,100)
win.show()
win.raise_()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment