QLabel显示图像,如视频

问题描述 投票:2回答:1

我试图让QLabel显示像视频一样的图像。

我希望这个显示我的图像从f0000.png到f0039.png慢慢看,所以我可以看到进展。

出于某种原因,我的for循环以50开头。

当我看到程序运行它只显示一个图像或它变化太快我无法看到进度。

如何解决它让它显示像视频的图像。

c++ qt5 qimage qlabel
1个回答
2
投票

您可以使用Qtimer并根据需要设置速度

标题:

#include <QMainWindow>
#include <QTimer>

namespace Ui
{
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow() override;

public slots:
    void updateLabel();

private:
    Ui::MainWindow *ui;
    QTimer* _timer;
    int index{0};
    QString pixResource{};
};

和impl。

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    _timer = new QTimer(parent);
    connect(_timer, SIGNAL(timeout()), this, SLOT(updateLabel()));
    _timer->start(1000);
}

MainWindow::~MainWindow()
{
    delete ui;
    _timer->stop();
    delete _timer;
}

void MainWindow::updateLabel()
{
    if (index >= 10)
    {
        index = 0;
    }
    qDebug() << "index: " << index;
    pixResource = "res/foo/image/" + QString::number(index)  + ".png";
    qDebug() << "now the res: " << pixResource;
    index++;
}
© www.soinside.com 2019 - 2024. All rights reserved.