Qt 中的 GIF 动画

发布于 2024-09-09 06:54:16 字数 253 浏览 7 评论 0原文

我使用了 QGraphicsViewQGraphicsScene 类来在小部件中显示图片,如下所示:

m_Scene->addPixmap(QPixmap(fileName));
m_View->setScene(m_Scene);

How I can show .gif Animation in the same场景?

I have used QGraphicsView, QGraphicsScene classes in order to show a picture in a widget like this:

m_Scene->addPixmap(QPixmap(fileName));
m_View->setScene(m_Scene);

How I can show .gif animation in the same scene?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

甲如呢乙后呢 2024-09-16 06:54:16

我不将 GIF 动画与 QGraphicsViewQGraphicsScene 一起使用,我仅在 QDialog 中使用它,但我认为这是相同的东西,所以在这里是我的代码:

QMovie *movie = new QMovie(":/images/other/images/16x16/loading.gif");
QLabel *processLabel = new QLabel(this);
processLabel->setMovie(movie);
movie->start();

我从链接获取的loading.gif


PS:另请查看 Qt SDK 中的示例。他们真的可以帮忙!

I don't use GIF animation with QGraphicsView or QGraphicsScene, I use it only in QDialog, but I think it's the same stuff, so here is my code:

QMovie *movie = new QMovie(":/images/other/images/16x16/loading.gif");
QLabel *processLabel = new QLabel(this);
processLabel->setMovie(movie);
movie->start();

My loading.gif I took from this link.


PS: also check the examples from Qt SDK. They are really can help!

呢古 2024-09-16 06:54:16

我把它放在这里以防我以外的人遇到同样的问题。

问题

GIF 无法加载,并且 isValid() 返回 false

代码

// Load animated GIF
QMovie* movie = new QMovie("foo.gif");

// Make sure the GIF was loaded correctly
if (!movie->isValid()) 
{
    // Something went wrong :(
}

// Play GIF
QLabel* label = new QLabel(this);
label->setMovie(movie);
movie->start(); 

解决方案

为了解决这个问题,我必须将 Qt 的 GIF 插件 qgif4.dll 放在名为 imageformats 的文件夹中在我的 exe 旁边,以便能够使用 GIF。

该dll可以在下面找到
/plugins/imageformats/qgif4.dll

I put this here in case someone other than me runs into the same problem.

Problem

The GIF would not load and isValid() returns false.

Code

// Load animated GIF
QMovie* movie = new QMovie("foo.gif");

// Make sure the GIF was loaded correctly
if (!movie->isValid()) 
{
    // Something went wrong :(
}

// Play GIF
QLabel* label = new QLabel(this);
label->setMovie(movie);
movie->start(); 

Solution

To solve this, I had to put Qt's GIF-plugin qgif4.dll in a folder named imageformats next to my exe to be able to use GIFs.

The dll can be found under
/plugins/imageformats/qgif4.dll.

那一片橙海, 2024-09-16 06:54:16

http://doc.qt.io/qt-5/qmovie.html

google 和 Qt 文档是你的朋友。甚至还有一个示例

PS:除非你在中国,否则谷歌是无法访问的,但你可以使用 Bing 和 doc.qt 之类的东西.io.com

PS2:要获得更深入的答案:您可以使用 QLabelQGraphicsProxyWidget,它通过 QLabel 具有 QMovie: :setMovie。可能有一种更简单/更短的方法来做到这一点。

http://doc.qt.io/qt-5/qmovie.html

google and Qt docs are your friend. There's even have an example.

PS: unless you're in China, then google is unaccessible, but you'd have stuff like Bing and doc.qt.io.com.

PS2: for a little more in-depth answer: you can use a QGraphicsProxyWidget of a QLabel which has a QMovie via QLabel::setMovie. There's probably an easier/shorter way to do it.

猫瑾少女 2024-09-16 06:54:16

给出正确的资源路径,如下代码所示

QMovie *movie=new QMovie(":/images/foo.gif");
if (!movie->isValid()) 
    {
     // Something went wrong :(
    }

// Play GIF
label=new QLabel(this);
label->setGeometry(115,60,128,128);
label->setMovie(movie);
movie->start();

Give the proper path of resource look like as below code

QMovie *movie=new QMovie(":/images/foo.gif");
if (!movie->isValid()) 
    {
     // Something went wrong :(
    }

// Play GIF
label=new QLabel(this);
label->setGeometry(115,60,128,128);
label->setMovie(movie);
movie->start();
北风几吹夏 2024-09-16 06:54:16

尝试使用正确的图像路径:

 QMovie *movie = new QMovie(":/images/mygif.gif");
 movie->setVisible(true);
 QLabel *processLabel = new QLabel(this);
 processLabel->setGeometry(200,150,180,100);
 processLabel->setVisible(true);
 processLabel->setMovie(movie);
 movie->start();

Try with proper image path:

 QMovie *movie = new QMovie(":/images/mygif.gif");
 movie->setVisible(true);
 QLabel *processLabel = new QLabel(this);
 processLabel->setGeometry(200,150,180,100);
 processLabel->setVisible(true);
 processLabel->setMovie(movie);
 movie->start();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文