gpt4 book ai didi

qt - Qlabel 和 Qtimer(需要让图像闪烁)

转载 作者:行者123 更新时间:2023-12-04 02:49:30 25 4
gpt4 key购买 nike

我有两个带有图像的 Q 标签,我需要每隔几秒闪烁一次。

我不明白如何使用 QLabel 实现它。

我现在的截图:

Screenshot with the example

最佳答案

创建一个 QTimer,将 timeout() 信号连接到一个槽,在槽中你可以对你的 QLabel 做任何你想做的事情!

我的类.h:

class MyClass : public QWidget
{
Q_OBJECT
public:
explicit MyClass(QWidget *parent = 0);

public slots:
void timeout();

private:
QTimer *timer;
QLabel *label;

int counter;
};

我的类.cpp:

#include "myclass.h"

MyClass::MyClass(QWidget *parent) :
QWidget(parent)
{
timer = new QTimer();

label = new QLabel();

counter = 0;

connect(timer, SIGNAL(timeout()), this, SLOT(timeout()));

timer->start(1000);
}

void MyClass::timeout()
{
if(counter%2)
label->setText("Hello !");
else
label->setText("Good bye...");
counter++;
}

关于qt - Qlabel 和 Qtimer(需要让图像闪烁),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18058291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com