本文介绍了QT:如何用动画一个QPropertyAnimation的QDeclarativeView的透明度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用QPropertyAnimation动画一个QDeclarativeView。但的透明度,它不work.It的任何改变,并没有错误,但我用财产几何体,它works.I没有想法。
下面是我的main.cpp code:
INT主(INT ARGC,CHAR *的argv [])
{
QApplication的一个(ARGC,ARGV,真正的);
QDeclarativeView *视图。
QDeclarativeContext *语境;
QDeclarativeEngine *引擎;
连接器*连接器; 鉴于=新QDeclarativeView(); 连接器=新的连接器();
上下文=取景> rootContext();
上下文> setContextProperty(连接器连接器);
上下文> setContextProperty(gRadioQMLDir的QDir :: currentPath());
取景>的SetSource(QUrl :: fromLocalFile(QML / Main.qml));
取景> setViewportUpdateMode(::的QGraphicsView MinimalViewportUpdate); 视图 - >显示();
QPropertyAnimation动画(看来,windowOpacity);
animation.setDuration(30000);
animation.setStartValue(0.0);
animation.setEndValue(1.0); animation.start();
返回a.exec();
}
解决方案
尝试使用QGraphicsOpacityEffect动画部件。示例:
的#include<&的QApplication GT;
#包括LT&;&QWidget的GT;
#包括LT&;&QDeclarativeView GT;
#包括LT&;&QGraphicsOpacityEffect GT;
#包括LT&;&QPropertyAnimation GT;
#包括LT&; QPushButton>INT主(INT ARGC,CHAR *的argv [])
{
QApplication的一个(ARGC,ARGV); QWidget的瓦;
QGraphicsOpacityEffect *透明度=新QGraphicsOpacityEffect;
QPropertyAnimation *动画=新QPropertyAnimation(不透明度不透明度); // QDeclarativeView * DV =新QDeclarativeView(安培; W)
// DV-> setFixedSize(200,200);
// DV-GT&; setGraphicsEffect(不透明度);
QPushButton * BTN =新QPushButton(按钮,&安培; W)
btn-> setGraphicsEffect(不透明度); anim-> setDuration(2000);
anim-> setStartValue(0.1);
anim-> setEndValue(1.0);
anim-> setEasingCurve(QEasingCurve :: InCubic);
anim->启动(); w.setFixedSize(300,200);
w.show(); 返回a.exec();
}
注:windowOpacity属性仅对那些窗口小部件是有效的。
I want to use QPropertyAnimation to animate the transparency of a QDeclarativeView .But,it doesn't work.It's nothing to change and no errors, but I use property "geometry",it works.I have no ideas.
Here is my main.cpp code:
int main(int argc, char *argv[])
{
QApplication a(argc, argv, true);
QDeclarativeView* view;
QDeclarativeContext *context;
QDeclarativeEngine* engine;
Connector* connector;
view = new QDeclarativeView();
connector = new Connector();
context = view->rootContext();
context->setContextProperty("Connector", connector);
context->setContextProperty("gRadioQMLDir", QDir::currentPath());
view->setSource(QUrl::fromLocalFile("qml/Main.qml"));
view->setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
view->show();
QPropertyAnimation animation(view, "windowOpacity");
animation.setDuration(30000);
animation.setStartValue(0.0);
animation.setEndValue(1.0);
animation.start();
return a.exec();
}
解决方案
Try to animate widget with using QGraphicsOpacityEffect. Sample:
#include <QApplication>
#include <QWidget>
#include <QDeclarativeView>
#include <QGraphicsOpacityEffect>
#include <QPropertyAnimation>
#include <QPushButton>
int main( int argc, char *argv[] )
{
QApplication a( argc, argv );
QWidget w;
QGraphicsOpacityEffect *opacity = new QGraphicsOpacityEffect;
QPropertyAnimation *anim = new QPropertyAnimation( opacity, "opacity" );
//QDeclarativeView *dv = new QDeclarativeView( &w );
//dv->setFixedSize( 200, 200 );
//dv->setGraphicsEffect( opacity );
QPushButton *btn = new QPushButton( "Button", &w );
btn->setGraphicsEffect( opacity );
anim->setDuration( 2000 );
anim->setStartValue( 0.1 );
anim->setEndValue( 1.0 );
anim->setEasingCurve( QEasingCurve::InCubic );
anim->start();
w.setFixedSize( 300, 200 );
w.show();
return a.exec();
}
Note: "windowOpacity" property is valid only for widgets that are windows.
这篇关于QT:如何用动画一个QPropertyAnimation的QDeclarativeView的透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!