Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top