PDA

View Full Version : How to display time in Progress Bar?



Gokulnathvc
10th August 2011, 11:44
How to display time in Progress Bar? In which, hours in one progress bar, minutes in one progress bar and seconds in another progress bar, and it should change as the clock?

wysota
10th August 2011, 13:45
Create three progress bars and a custom slot connected to a timer that sets the progress bars according to the current time.

Gokulnathvc
11th August 2011, 12:53
I have used the following code: but it does nothing.. Please help me in fixing this:


#include "dialog.h"
#include "ui_dialog.h"
#include "QDateTime"
#include "QTimer"

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

ui->m_hours->setValue(0);
ui->m_minutes->setValue(0);
ui->m_seconds->setValue(0);
ui->m_hours->setRange(0,23);
ui->m_minutes->setRange(0,59);
ui->m_seconds->setRange(0,59);

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(prgCtrl()));
timer->start();


}

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

void Dialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}


void Dialog::prgCtrl()
{
dt= QDateTime::currentDateTime();
ui->m_hours->setValue(dt.time().hour());
ui->m_minutes->setValue(dt.time().minute());
ui->m_seconds->setValue(dt.time().second());
}

wysota
11th August 2011, 13:07
Why would it do anything if you assign the same values every time?

Lesiok
11th August 2011, 17:37
wysota, this is current time not this same value.
Gokulnathvc, what is it does nothing ? This code looks good. Show us rest of code, especially how You create an instance of Dialog.

stampede
11th August 2011, 19:49
Is void Dialog:: prgCtrl(); declared as slot ?


void Dialog::prgCtrl()
{
dt= QDateTime::currentDateTime();
qDebug() << "update" << dt;
ui->m_hours->setValue(dt.time().hour());
ui->m_minutes->setValue(dt.time().minute());
ui->m_seconds->setValue(dt.time().second());
}

Can you see the debug message ?
Another thing is that you can set one second interval for timer, IMHO there is no need for more frequent ui updates in that case.

Lykurg
11th August 2011, 21:45
wysota, this is current time not this same value.Look at what time wysota has answered and at what time Gokulnathvc has edited his post the last time. This is, by the way, not a very polite way to alter his posts...

Gokulnathvc
12th August 2011, 05:56
I have modified my program after Wysota's advice and then i edited here.

wysota
12th August 2011, 11:56
I have modified my program after Wysota's advice and then i edited here.

And then you forgot to mention that it works now. Sometimes I think 6 hours is too long to allow people to edit their posts.