如何在显示/隐藏期间在 QTDialog 中添加效果?
Posted
技术标签:
【中文标题】如何在显示/隐藏期间在 QTDialog 中添加效果?【英文标题】:How to add effects in QTDialog during show/hide? 【发布时间】:2014-09-22 09:24:16 【问题描述】:当用户点击显示对话框时,有什么方法可以添加对话框从小尺寸到最大尺寸的效果! 就像在 iphoto 中,当我们请求打开一个对话框时,它以同样的方式出现!!! 我正在使用的代码是:
fade_effect = new QGraphicsOpacityEffect(this);
this->setGraphicsEffect(fade_effect);
animation = new QPropertyAnimation(fade_effect, "opacity");
animation->setEasingCurve(QEasingCurve::InOutQuad);
animation->setDuration(5000);
animation->setStartValue(1);
animation->setEndValue(0.01);
animation->start(QPropertyAnimation::DeleteWhenStopped);
this->setWindowOpacity(0.5);
//this->hide();
//QDialog::reject();
它在隐藏的情况下不起作用。
【问题讨论】:
看看QPropertyAnimation
是否适合你。
您添加的代码示例与您的要求存在争议。如果您想获得其他信息,请提出新问题。
【参考方案1】:
Qt Animation Framework 为您提供了很多创建动画效果的工具。这是一个示例,您可以如何使用QPropetyAnimation
实现您的目标:
void YourWindowClass::showEvent(QShowEvent* e)
//create animation for "geometry" property
QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
//duration in ms
animation->setDuration(500);
//starting geometry
QRect startRect(900,500,100,100);
//final geometry
QRect endRect(750,350,400,400);
animation->setStartValue(startRect);
animation->setEndValue(endRect);
//starts animation which will be deleted when finished
animation->start(QAbstractAnimation::DeleteWhenStopped);
【讨论】:
您好,请查看上面的代码。它不起作用。 什么完全不起作用?我在发布之前检查了此代码。 您的示例是用于移动小部件,而不是用于更改不透明度。 @BЈовић 哪里说需要改变不透明度?阅读问题。代码是后来添加的。 正确。此外,他的代码没有反映所要求的内容以上是关于如何在显示/隐藏期间在 QTDialog 中添加效果?的主要内容,如果未能解决你的问题,请参考以下文章