[PySide] animate QStackedLayout?

Frank Rueter | OHUfx frank at ohufx.com
Wed Apr 11 02:19:56 CEST 2012


Hi Aaron,

hope you had a good Easter.
Thanks again for the example! It makes total sense I and kinda should 
have known that myself by now ;).
I am now wondering if it's maybe best to create a dictionary that holds 
the buttons as keys and the respective pages as values. Would anything 
speak against that approach?

I also have a couple of questions about your code changes (just want to 
understand things properly and learn the best practices):

in line 101, why are you using xrange to loop through the list items 
rather than the straight forward approach of cycling through the list's 
contents? Is this faster? You have to sort the list twice this way and 
the code seems less intuitive, so I'm just wondering about the benefits.

in line 106 you added "self" to the QPushButton's arguments, even though 
the button gets added into a layout that is already parented to the 
widget, so the button becomes a descendent of "self" automatically, 
right?! At least that's how I understood the documentation.


Thanks again for your fantastic help, it's invaluable for me right now!!

Cheers,
frank

On 4/10/12 9:07 PM, Aaron Richiger wrote:
> Hello Frank!
>
> Easter is over, so it's time to code... Passing a variable to a lambda 
> function multiple times in a loop does not work here. So, the only 
> thing I changed in your code was: Connect the clicked event of the 
> buttons with a method without parameters and therefore write a wrapper 
> "pageChangeRequest()" to evaluate the clicked button, the 
> corresponding page and finally change the page in the animator. You 
> can see your modified code here:
>
> http://pastebin.com/Mzd8minm
>
> Evaluating the sender of a signal with self.sender() was helpful for 
> me quite often, but always keep in mind, that this only works in 
> classes derived from QObject (which is the case in your code, since 
> your ToolBrowser is inheriting from QWidget). So you always have to 
> work with classes when using this functionality.
>
> Happy coding!
> aaron
>
>
>
>
>> Hi Aaron,
>>
>> I've modified your example code in an attempt to make it dynamic 
>> based on a given data set.
>> The data is a nested dictionary of this form:
>>     data = dict(
>>         containerA= (
>>            dict(CatAA=['A1', 'B1', 'C1'],
>>                 CatAB=['A2', 'B2', 'C2'],
>>                 CatAC=['A3', 'B3', 'C3'])),
>>         containerB= (
>>            dict(CatBA=['A4', 'B4', 'C4'],
>>                 CatBB=['A5', 'B5', 'C5'],
>>                 CatBC=['A6', 'B6', 'C6'])),
>>         containerC= (
>>            dict(CatCA=['A7', 'B7', 'C7'],
>>                 CatCB=['A8', 'B8', 'C8'],
>>                 CatCC=['A9', 'B9', 'C9'])))
>>
>> I now have to create buttons dynamically based on how the containers 
>> and categories in this data set (and eventually figure out how to 
>> also take the categories' contents into account and generate buttons 
>> for those as well, which can be controlled by Animator instance).
>> At the moment I'm running into the problem that when I create an 
>> instance of a "WidgetPage" inside a loop and hand it over to your 
>> Animator (see line 113), the bindings go all wrong of course and the 
>> pages all end up at the same memory address, thus overwriting each other.
>> I tried copy.deepcopy (see line 111) but that seems to barf with 
>> class instances.
>>
>> Here is my full code:
>> http://pastebin.com/txzstwJV
>>
>> Any ideas?
>>
>> Cheers and thanks again for this awesome example!
>> frank
>>
>>
>> On 4/8/12 6:13 AM, Aaron Richiger wrote:
>>> Thanks Juande for pointing this out. Fixed it in the following 
>>> version at pastebin:
>>>
>>> Only one page visible:
>>> http://pastebin.com/kP1rdLHx
>>>
>>> Good luck with finding the eggs!
>>>
>>>
>>>> Hi Aaron,
>>>>
>>>> Pretty cool your solutions!
>>>>
>>>> Just a comment about animated_widgets_with_only_one_widget, there 
>>>> is an visibility issue when window is resize.
>>>>
>>>> Happy Easter!
>>>> Juande
>>>>
>>>>> Hello Frank!
>>>>>
>>>>> I slightly changed my code to your new informations and added 
>>>>> comments for better understanding;-)! I also changed the sorting 
>>>>> method to show you a possibility to separe checked from unchecked 
>>>>> checkboxes. Because I first thought, that multiple pages must be 
>>>>> visible at once, I created two versions, but according to your 
>>>>> mail, the second possibility will meet your requirements closer I 
>>>>> guess. But the multi-version might be interesting for others:
>>>>>
>>>>> Mutliple pages visible:
>>>>> http://pastebin.com/hW0zeL4P
>>>>>
>>>>> Only one page visible:
>>>>> http://pastebin.com/cjn0UuA9
>>>>>
>>>>> Easter-greetings
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Am 07.04.2012 01:51, schrieb Frank Rueter | OHUfx:
>>>>>> I agree, it does seem off, which is why I'm throwing it out here 
>>>>>> to get some ideas on how to tackle this from more experienced peeps.
>>>>>>
>>>>>> I will try to clarify what I'm after:
>>>>>> The idea is to have a collection of buttons per category, let's 
>>>>>> say a "page" of buttons. When the category is chosen via the 
>>>>>> buttons on the left, the requested page with buttons slides into 
>>>>>> view pushing the current one out of view. It's like an animated 
>>>>>> toolbox.
>>>>>>
>>>>>> I like your suggestion, will investigate.
>>>>>>
>>>>>> Cheers,
>>>>>> frank
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 6/04/12 11:31 PM, Sebastian Elsner wrote:
>>>>>>> This Approach seems really off, Frank. I am not really getting 
>>>>>>> what you want to do, maybe you can give us the specific purpose 
>>>>>>> of this... What I could imagine is using a QScrollArea, which 
>>>>>>> makes a QGridLayout scrollable.
>>>>>>>
>>>>>>>
>>>>>>> Am 06.04.2012 09:13, schrieb Frank Rueter | OHUfx:
>>>>>>>> yes, I think I'm starting to get it, thanks.
>>>>>>>>
>>>>>>>> So here is a very rough and ugly test using a single animated 
>>>>>>>> table (feel free to laugh):
>>>>>>>> http://pastebin.com/PbZ8ismH
>>>>>>>>
>>>>>>>> I am trying to see if it's feasible to stuff all my widgets 
>>>>>>>> into one big table, then animate the table's position so that 
>>>>>>>> only the requested column(s) are within the view according to 
>>>>>>>> which button is pushed on the left hand side. Obviously I'd 
>>>>>>>> have to hide the headers and lines etc. (no idea how to do that 
>>>>>>>> yet either).
>>>>>>>>
>>>>>>>> What do people think how best to approach this? The above 
>>>>>>>> doesn't feel right and I'd have to do a lot of hacking to make 
>>>>>>>> this look pretty (though the animation is easy to control as 
>>>>>>>> it's just one widget). Or should I rather create one table per 
>>>>>>>> button and move them around as a group (I guess I could hide 
>>>>>>>> the unwanted tables as well then).
>>>>>>>>
>>>>>>>> Or does anyone have completely different ideas how to tackle 
>>>>>>>> this? I'm sure there is a way more elegant solution.
>>>>>>>> I'm  still trying to stick to default QT stuff before I dive 
>>>>>>>> into Qt Quick and such.
>>>>>>>>
>>>>>>>> Thanks for all the help and pointers so far!
>>>>>>>>
>>>>>>>> frank
>>>>>>>>
>>>>>>>>
>>>>>>>> On 4/6/12 6:28 PM, Tibold Kandrai wrote:
>>>>>>>>> Hi!
>>>>>>>>>
>>>>>>>>> Exactly! Instead of QAnimationGroup you have to use 
>>>>>>>>> QParallelAnimationGroup 
>>>>>>>>> <http://qt-project.org/doc/qt-4.8/qparallelanimationgroup.html>orQSequentialAnimationGroup 
>>>>>>>>> <http://qt-project.org/doc/qt-4.8/qsequentialanimationgroup.html>.
>>>>>>>>> Or you can create your own group by subclassing 
>>>>>>>>> QAnimationGroup if you have special needs. :)
>>>>>>>>>
>>>>>>>>> Cheers,
>>>>>>>>> Tibold
>>>>>>>>>
>>>>>>>>> On 06/04/2012 06:45, Frank Rueter | OHUfx wrote:
>>>>>>>>>> I think I found the problem in the fact that it's an abstract 
>>>>>>>>>> class and not meant to be used directly.
>>>>>>>>>> the joy of learning new stuff....
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 4/6/12 4:05 PM, Frank Rueter | OHUfx wrote:
>>>>>>>>>>> Thanks again for this tip Tibold. It seems to be what I'm 
>>>>>>>>>>> after, though I just discovered that QAnimationGroup doesn't 
>>>>>>>>>>> seem to be supported in PySide. I got this error when I 
>>>>>>>>>>> tried to create an instance of it:
>>>>>>>>>>>
>>>>>>>>>>> NotImplementedError: 'QAnimationGroup' represents a C++ 
>>>>>>>>>>> abstract class and cannot be instantiated
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> I will try and add all widgets to one "page" widget 
>>>>>>>>>>> (whatever that may be, I need to find out yet), and then 
>>>>>>>>>>> apply the animation to that.
>>>>>>>>>>> Fingers crossed...
>>>>>>>>>>>
>>>>>>>>>>> Cheers,
>>>>>>>>>>> frank
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 4/4/12 7:29 PM, Tibold Kandrai wrote:
>>>>>>>>>>>> Hey!
>>>>>>>>>>>>
>>>>>>>>>>>> Try QtAnimation:
>>>>>>>>>>>> http://qt-project.org/doc/qt-4.8/animation-overview.html
>>>>>>>>>>>>
>>>>>>>>>>>> I use it with in a QGraphicsWidget, but this should work everywhere AFAIR.
>>>>>>>>>>>>
>>>>>>>>>>>> Cheers,
>>>>>>>>>>>> Tibold
>>>>>>>>>>>>
>>>>>>>>>>>> On 04/04/2012 06:46, Frank Rueter | OHUfx wrote:
>>>>>>>>>>>>> Hi everyone,
>>>>>>>>>>>>>
>>>>>>>>>>>>> I'm very new to Qt/PySide and am wondering if it's possible to add an
>>>>>>>>>>>>> animation effect to, let's say, QStackedLayout, for when the page
>>>>>>>>>>>>> changes. I guess it'd something similar to the way the AppStore works.
>>>>>>>>>>>>>
>>>>>>>>>>>>> In this example I'd like to see the new button "push" the old button out
>>>>>>>>>>>>> of view when the combobox changes:
>>>>>>>>>>>>> http://pastebin.com/i5sFgQzE
>>>>>>>>>>>>>
>>>>>>>>>>>>> I'm happy to take a good ol' fashioned RTFM, I'm just having a hard time
>>>>>>>>>>>>> finding the right bit of information out there.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Any help would be greatly appreciated.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Cheers,
>>>>>>>>>>>>> frank
>>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>>> PySide mailing list
>>>>>>>>>>>>> PySide at qt-project.org
>>>>>>>>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>> PySide mailing list
>>>>>>>>>>>> PySide at qt-project.org
>>>>>>>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> _______________________________________________
>>>>>>>>>>> PySide mailing list
>>>>>>>>>>> PySide at qt-project.org
>>>>>>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> _______________________________________________
>>>>>>>>>> PySide mailing list
>>>>>>>>>> PySide at qt-project.org
>>>>>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>>>>>>>
>>>>>>>>> -- 
>>>>>>>>> Tibold Kandrai,
>>>>>>>>> CEO @ Dotz Team I/S,
>>>>>>>>> Software developer, consultant
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> PySide mailing list
>>>>>>>>> PySide at qt-project.org
>>>>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>>>>>>
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> PySide mailing list
>>>>>>>> PySide at qt-project.org
>>>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> PySide mailing list
>>>>>>> PySide at qt-project.org
>>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> PySide mailing list
>>>>>> PySide at qt-project.org
>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> PySide mailing list
>>>>> PySide at qt-project.org
>>>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> PySide mailing list
>>> PySide at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>
>>
>> _______________________________________________
>> PySide mailing list
>> PySide at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/pyside
>
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20120411/6529f028/attachment.html>


More information about the PySide mailing list