点击查看代码
m_nameLabel=new QLabel("我是传奇",this);
//m_nameLabel->show();
m_nameLabel->resize(70,50);
m_nameLabel->setAlignment(Qt::AlignCenter);
m_nameLabel->move(50,50);
QPalette palette;
palette.setColor(QPalette::Background,QColor(0,255,0));
m_nameLabel->setPalette(palette);
m_nameLabel->setAutoFillBackground(true);
QGraphicsOpacityEffect *pButtonOpacity = new QGraphicsOpacityEffect(this);
pButtonOpacity->setOpacity(1);
m_nameLabel->setGraphicsEffect(pButtonOpacity);
QPropertyAnimation *pOpacityAnimation1 = new QPropertyAnimation(pButtonOpacity, "opacity");
pOpacityAnimation1->setDuration(5000);
pOpacityAnimation1->setStartValue(1);
pOpacityAnimation1->setEndValue(0);
QPropertyAnimation *pOpacityAnimation2 = new QPropertyAnimation(pButtonOpacity, "opacity");
pOpacityAnimation2->setDuration(2000);
pOpacityAnimation2->setStartValue(0);
pOpacityAnimation2->setEndValue(1);
QSequentialAnimationGroup *pOpacityGroup = new QSequentialAnimationGroup(this);
//pOpacityGroup->addPause(1000);
pOpacityGroup->addAnimation(pOpacityAnimation1);
//pOpacityGroup->addAnimation(pOpacityAnimation2);
pOpacityGroup->start();
//m_group = new QParallelAnimationGroup(this);
//m_group->addAnimation(pOpacityGroup);
//m_group->start();
效果如下: