QT SplashScreen带有褪色徽标未运行动画
Qt SplashScreen w/ Fading Logo Not Running Animation
我正在为我的应用创建一个加载屏幕,我想实现两个Qlabels(背景和覆盖),其中覆盖只是背景的发光轮廓。我希望这个叠加层以不透明(0.0-1.0)淡入淡出(0.0-1.0),我将Qpropertyanimation与标签的WindousOpacity属性一起使用,但对此无济于事。这是我的完整源代码。
main.cpp:
#include "mainwindow.h"
#include "imagefade.h"
#include <QApplication>
#include <QSplashScreen>
#include <QTimer>
#include <QHBoxLayout>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSplashScreen *splashScreen = new QSplashScreen();
splashScreen->resize(500, 500);
QPixmap bkgdImage(":/Files/Images/Launch/launch.png");
QPixmap ovlyImage(":/Files/Images/Launch/launch-glow.png");
ImageFade *imageLabel= new ImageFade(splashScreen);
imageLabel->setBackgroundImage(bkgdImage);
imageLabel->setOverlayImage(ovlyImage);
imageLabel->startAnimation(5000);
splashScreen->show();
MainWindow w;
QTimer::singleShot(2500, splashScreen, SLOT(close()));
QTimer::singleShot(2500, &w, SLOT(show()));
//w.show();
return a.exec();
}
imagefade.cpp:
#include "imagefade.h"
#include <QDebug>
ImageFade::ImageFade(QWidget *parent) : QWidget(parent)
{
bkgdLabel = new QLabel();
ovlyLabel = new QLabel();
bkgdLabel->setGeometry(QRect(QPoint(0, 0), QSize(parent->size())));
ovlyLabel->setGeometry(QRect(QPoint(0, 0), QSize(parent->size())));
fadeAnimation = new QPropertyAnimation(ovlyLabel, "windowOpacity");
fadeAnimation->setLoopCount(5);
fadeAnimation->setStartValue(1.0);
fadeAnimation->setEndValue(0.0);
fadeAnimation->setEasingCurve(QEasingCurve::OutQuad);
connect(fadeAnimation, SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)), this, SLOT(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));
}
ImageFade::~ImageFade()
{
//fadeAnimation->stop();
}
void ImageFade::setBackgroundImage(QPixmap bkgdImg)
{
this->bkgdImg = bkgdImg;
bkgdLabel->setPixmap(bkgdImg.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
void ImageFade::setOverlayImage(QPixmap ovlyImg)
{
this->ovlyImg = ovlyImg;
ovlyLabel->setPixmap(ovlyImg.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
void ImageFade::startAnimation(int fadeDelay)
{
fadeAnimation->setDuration(fadeDelay);
fadeAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
void ImageFade::stop()
{
fadeAnimation->stop();
}
void ImageFade::stateChanged(QAbstractAnimation::State state1, QAbstractAnimation::State state2)
{
qDebug() << state1 << state2;
}
imagefade.h:
#ifndef IMAGEFADE_H
#define IMAGEFADE_H
#include <QWidget>
#include <QLabel>
#include <QLabel>
#include <QPropertyAnimation>
class ImageFade : public QWidget
{
Q_OBJECT
public:
explicit ImageFade(QWidget *parent = nullptr);
~ImageFade();
void setBackgroundImage(QPixmap bkgdImg);
void setOverlayImage(QPixmap ovlyImg);
void startAnimation(int fadeDelay);
void stop();
signals:
public slots:
void stateChanged(QAbstractAnimation::State state1, QAbstractAnimation::State state2);
private:
QLabel *bkgdLabel;
QLabel *ovlyLabel;
QPixmap bkgdImg;
QPixmap ovlyImg;
QPropertyAnimation *fadeAnimation;
};
#endif // IMAGEFADE_H
我几天前也遇到了同样的问题。我可以分享您的代码如何使用动画隐藏/显示标签。
QGraphicsOpacityEffect *opacity;
opacity = new QGraphicsOpacityEffect("label_name");
ui->"label_name"->setGraphicsEffect(opacity);
QPropertyAnimation *anim = new QPropertyAnimation(opacity, "opacity");
anim->setEasingCurve(QEasingCurve::Linear);
anim->setStartValue(1.0);
anim->setEndValue(0.01);
anim->setDuration(1000);
anim->start(QAbstractAnimation::DeleteWhenStopped);
这是一个很小的示例,如何使用qpropertyanimation隐藏Qlabel。如果您设置启动值0.01 和末端值1.0
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 运行同一解决方案的另一个项目的项目
- CMake-按正确顺序将项目与C运行时对象文件链接
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 代码在main()中运行,但在函数中出现错误
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 如何在运行中期切换GTK CSS style_context
- 如何在MS Visual Studio 2019中运行QT UI
- 如何通过cpp程序运行shell脚本
- IPC使用多个管道和分支进程来运行Python程序
- 删除指向指针的指针是运行时错误吗
- 如何用参数值调用函数(仅在运行时已知)
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- QT SplashScreen带有褪色徽标未运行动画
- cocos2dx运行从cocos studio导出的Json到动画
- 程序特定的OpenGL运行时错误:多个输入缓冲区蒙皮动画
- 所有行星在动画时都以相同的速度围绕太阳运行