[SOLVED] Slide Animation and Layout
-
Dear all,
I am trying to create a slide animation on a widget. The idea is that a main widget stays where it is and triggers the slide effect on the other widget. Here I try to have the former below the latter.
What I have achieved is first to animate the slide-widget, as you can see "in this video":http://videobin.org/+51x/5g8.html.
Next I applied an animation effect to the main window (parent widget) so as to follow the same motion as the slide-widget. However the result wasn't as expected, as you can see "on this other video":http://videobin.org/+51y/5g9.html.Now at first the second didn't work: the height of the main widget didn't change. So I changed the sizeConstraint of all layouts to SetNoConstraint, which led to the 2nd video example. Obviously the result is not what I want: the bottom button shouldn't appear to move, nor to be resized.
How can I achieve that? What is the problem? Is it a layout issue? Is a grid layout perhaps a better way to organise this? (I must say I am a bit confused when it comes to size and position in Qt (between geometry, hints, constaints, policies, minimums and maximums, I'm not sure what is what any more...).
Thanks for your help.
Benjamin
Here is the code:@#!/usr/bin/env python
import sysfrom 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_())
@ -
The problem was solved by removing all @ self.layout.setSizeConstraint(QtGui.QLayout.SetNoConstraint)@ and by adding a @ self.dashboard.label.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Ignored)@ just before the animation starts.