PDA

View Full Version : Technique for creating a main window that can be programatically resized and animated



Berryblue031
29th June 2011, 13:25
I've been working on an app that has some special behavior.

At the top level it is a frameless widget that can be shown just as a "toolbar" that is docked to the top of the users monitor when the user enters a search word in the toolbar it expands downwards to show results. The program can also "autohide" itself and be re-shown when the user mouses over it, for the autohiding I render the content widget as a pixmap, hide the real content and show a qlabel with the pixmap this way I was able to prevent the content from getting distorted and specify alignment as it animates out. In the different states the program also has a different minimum size.

From the very beginning I have had problems with the program not redrawing itself properly as it was being dynamically resized and had to implement an ugly little hack function I call refresh that invalidates layouts, calls updategeometry and repaint. In one situation i actually move the program 1px and then move it back (otherwise it just refused to redraw itself with the updated geometry)

Now I am porting my program to mac, and my "refresh" function is causing flicker
Does anybody have any advice on how I should have implemented this top level expanding / compacting widget?

MarekR22
29th June 2011, 13:44
From your description it looks like that you messed up something in your code, most of this things should work out of the box.
For animation you have QPropertyAnimation.

Berryblue031
29th June 2011, 14:24
I am using QPropertyAnimation.

It is not out of the box, top level widgets in Qt do not automatically re-size to fit their contents

I am programmatically resizing the top level widget when the child widget that contains the toolbar and results pane shows and hides the results pane. There is also a notification area which when it shows notifications expands the top level widget and when the notifications are hidden and the top level widget is resized back to its original size the, When this happens the searchwidget updates itself to take over the space of the notification widget but does not take into account the now smaller size of the top level widget.

My structure is like this

topFramelessWidget
- NotificationWidget
- SearchWidget
------- ToolbarWidget
------- ResultsPaneWidget

I am not sure maybe the things i do in my refresh function are necessary on windows everything appears smoothly but on mac its like you can see when it repaints it shows blank and then draws the content it looks really awful when it blinks like that