简体   繁体   English

Qt:动画化QWidget的“滚动”

[英]Qt: Animating the 'roll down' of a QWidget

I have a QWidget that contains various other widgets. 我有一个包含各种其他小部件的QWidget。 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. 我想通过从上向下逐渐显示它,以使其出现在屏幕上的动画效果,将其高度从0增加到自然的高度。

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. 这有两个问题:-当高度达到一定高度时崩溃,并显示“ qDrawShadeRect:无效参数”错误。 - 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. -如果将0更改为100,则可以正常工作,但是要设置动画的QWidget中包含的控件的布局会随着动画的改变而改变,开始挤在一起并随着空间的增加逐渐散开。 This looks ugly! 这看起来很丑!

Does anyone have any suggestions? 有没有人有什么建议?

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. 由于窗口小部件的裁剪,这意味着该窗口小部件将在动画时显示全尺寸窗口小部件的一部分。

For the crash, I'd recommend grabbing a stack trace and, assuming the problem isn't in your code, report it as a bug . 对于崩溃,我建议获取堆栈跟踪,并假设问题不在您的代码中, 请将其报告为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 将QStackWidget与两个项目一起使用:实际的小部件和所需的小部件
  • The desired widget is really just a QWidget::render() to a pixmap of what you want the widget to look like. 所需的小部件实际上只是QWidget :: render()到您希望小部件的外观的像素图。
  • For the animation, show the pre-rendered widget and then switch once you've reached the target size. 对于动画,显示预渲染的小部件,然后在达到目标大小后进行切换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM