2014-09-22 22 views
-2

当用户点击以显示对话框时,是否有任何方法可以添加效果,如对话框以小尺寸显示最大尺寸! 当我们要求打开一个对话框时,就像在iphoto中一样,它以相同的方式出现! 我使用的代码是:如何在显示/隐藏期间在QTDialog中添加效果?

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(); 

它不是躲在情况下工作。

+3

看看['QPropertyAnimation'(http://qt-project.org/doc/qt-4.8/qpropertyanimation.html)将用于工作您。 – thuga 2014-09-22 09:34:30

+0

您添加的代码示例对您所问的内容有争议。如果你想获得另一个信息,请提出一个新问题。 – Ezee 2014-09-24 08:31:28

回答

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); 
} 
+0

嗨,请看看上面的代码。它不工作。 – user2098173 2014-09-23 05:15:30

+0

什么exacly不起作用?在发布之前我检查了这个代码。 – Ezee 2014-09-23 05:45:10

+0

你的例子是移动一个小部件,而不是改变不透明度。 – 2014-09-24 06:24:46