Qt - 如何在对话框上发布横幅?

发布于 2024-09-05 03:11:53 字数 224 浏览 2 评论 0原文

我有一个目录,其中有几张图片和 gif 动画。我想以无限循环的方式将图片和动画发布在 QDialog 上(通过以 2 分钟间隔循环更改图片),并且在这些图片和动画上我想设置一个链接,以便当您单击浏览器时打开设置的链接。

我怎么能做到这一点?

请考虑我知道如何获取目录中的所有 .jpg amd .gif 文件名(完整路径)。考虑有一个QStringList fileNameList;其中包含完整路径。

I have a directroy where I have several pictures and gif animations. I want to post that pictures and animations on a QDialog in an infinite loop (by cyclically changing pictures in 2 minutes interval) and on that pictures and animations I want to set a link so that when you click the browser open the set link.

How I could do this?

Please consider that I know how to get all .jpg amd .gif file names (full path) in the directory. Consider there is a QStringList fileNameList; which contains that full paths.

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

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

发布评论

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

评论(2

简单爱 2024-09-12 03:11:53

为此,您可以使用 2 个 QLabel。第一个用于静态图像(如 jpg),第二个用于动画。在第一个中,您可以使用 setPixmap 来设置图像,在第二个中,您需要创建一个 QMovie 对象,并在构造函数中为其提供 gif 文件。创建对象后,您可以使用 setMovie() 函数将影片分配给标签。

在您调用 QMovie 对象中的 start() 之前,电影不会开始。

这样你就有了动画和静态图像。由于您希望每 2 秒更改一次,因此我建议将所有文件名存储在 QList 中,然后使用 QTimer 读取下一个文件名并将其加载到其中一个标签中(用于静态图像的标签或另一个标签),然后隐藏不可见的那个。

要打开链接,您可以子类化 QLabel 类并重写 mousePressEvent 方法。在该方法内,您可以调用 QDesktopServices::openExternalLink(link)。您可以将该链接添加为子类的成员。

祝你好运!

You can use 2 QLabels for this. The first one will be used for static images like jpg and the second one for animations. In the first one you can use setPixmap to set the image and in the second one you need to create a QMovie object giving it the gif file in the constructor. Once the object is created you can assign the movie to a label using the setMovie() function.

The movie doesn't start until you call start() in the QMovie object.

With this you have animations and static images. Since you want then change every 2 seconds I would suggest to store all the file names in a QList and then use a QTimer to read the next file name and load it in one of the labels (the one for static images or the other) and hide the one that is not going to be visible.

To open links you can subclass the QLabel class and override the mousePressEvent method. Inside the method you can call QDesktopServices::openExternalLink(link). You can add the link as a member of your subclass.

Good luck!

蓝咒 2024-09-12 03:11:53

您可以使用 QLabel::setPixmap 在中显示图像一个标签。

You can use QLabel::setPixmap to show an image in a label.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文