Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Slide Animation and Layout
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Slide Animation and Layout

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 13.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jesuisbenjamin
    wrote on last edited by
    #1

    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 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_())
    @

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jesuisbenjamin
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved