views:

172

answers:

2

I have a QWidget that contains various other widgets. I want to animate it appearing on the screen by gradually revealing it from the top down, increasing it's height from 0 to whatever it's natural height would be.

The way I have it currently is:

mAnimation = new QPropertyAnimation(this, "maximumHeight");
mAnimation->setStartValue(0);
mAnimation->setEndValue(400);
mAnimation->start();  

This has two issues: - It crashes when the height reaches a certain height, with a "qDrawShadeRect: Invalid parameters" error. - If I change the 0 to 100, it works fine, but the widgets contained within the QWidget I'm animating have their layout changed as the widget animates, starting very squashed together and gradually spreading apart as they get more space. This looks ugly!

Does anyone have any suggestions?

+1  A: 

For the second problem, I would suggest wrapping everything inside the widget in another widget, which has a fixed size. Due to the clipping of widgets, this means the widget will show portions of the fully-sized widgets while it animates.

Caleb Huitt - cjhuitt
I attempted this before, but couldn't manage to get the inner widget to size. I want to avoid calculating the size of the inner widget manually. I tried adding it to a layout to grab the correct size, then setting it manually, but it seems the layouts don't immediately lay out the widgets so it was returning incorrect sizes.If I could solve this, it'd work!
eAi
A: 

For the crash, I'd recommend grabbing a stack trace and, assuming the problem isn't in your code, report it as a bug.

For the second, rather than render the widget exactly where you want it with different sizes, render it as you'd like it to be seen. For example:

  • Use a QStackWidget with two items: the actual widget and the desired widget
  • The desired widget is really just a QWidget::render() to a pixmap of what you want the widget to look like.
  • For the animation, show the pre-rendered widget and then switch once you've reached the target size.
Kaleb Pederson