custom widget with progressbar (timeline animation on it) Qt c++

142 views Asked by At

I have a question. I created a custom widget with an animated progressbar. But when i start my application it does not work, the animation does not start.

Explanation:

I created a progressbar with them name: timeLeft

I have also created a QDialog and when it will be accepted, the function progressBar() get called.

startWindow is my mainwindow.

When timeline is going to finish, a function called timeover() get called in startWindow.

Timeover() activates a label with the text "Time is over".

Loadfrom() is a function of startWindow ->It load a Textfile in a Vector and the QString time is either "0" or "1".

If its "0" or "1", is defined in the QDialog where you can choose, if progressbar is active or not.

Ps everything is connected in header file and the code down there is from the custom widget.

#include "timeline.h"
#include "ui_timeline.h"
#include "startwindow.h"

timeLine::timeLine(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::timeLine)
{
    ui->setupUi(this);
}

timeLine::~timeLine()
{
    delete ui;
}

void timeLine::configurateBar() {
    ui->timeLeft->setValue(0);
    ui->timeLeft->setTextVisible(false);
    ui->timeLeft->setRange(0, 100);
    
    //ruft Funktion in startWindow auf
    startWindow startWindow;
    QVector<QString> settings = startWindow.loadFrom(OutputFolder +"/logs/settings.txt");
    QString time = settings[3];
    
    if(time == "1") {
        ui->timeLeft->setStyleSheet("QProgressBar {border: 1px solid white; background-color: transparent; } QProgressBar::chunk { background-color: rgba(2, 65, 118, 255);}");
        timeline->start();
    } else {
        ui->timeLeft->setStyleSheet("background-color: transparent; border: 0;");
    }
}

void timeLine::progressBar() {
    configurateBar();
    
    //Zeitlichbegrenzte ProgressBar
    auto timeline = new QTimeLine(10000, this);
    timeline->setFrameRange(0, 100);
    connect(timeline, &QTimeLine::frameChanged, ui->timeLeft, &QProgressBar::setValue);
        
    //Zeit abgelaufen
    startWindow startWindow;
    connect(timeline, SIGNAL(finished()), &startWindow, SLOT(timeover()));
}
0

There are 0 answers