|
 |
Can we change the values in QwtThermo dynamically? |
srinivasj
Coder

Registration Date: 09.05.2008
Posts: 17
Level: 5 [?]
Experience: 124
Next Level: 173
 |
|
| Can we change the values in QwtThermo dynamically? |
 |
[COLOR=darkblue]Using a timer event I am trying to change the values in the QWT thermo.
For every timer event I want to show different values on the thermo.
But in my case it is not happening.
Only the value at the first timer event is shown on the thermoafter that the values on QWT thermo are not getting refreshed.
Please provide me a solution to refresh the values on QwtThermo.
Code :
#include<qapplication.h>
#include <qgroupbox.h>
#include <qlayout.h>
#include <qpainter.h>
#include <qlabel.h>
#include <iostream>
#include <qframe.h>
#include <qwt_thermo.h>
#include <sys/time.h>
#include <signal.h>
using namespace std;
class SysInfo ;
SysInfo *info;
int iteration = 10 ;
int timerId;
double sri = 10;
QLabel *d_timelabel;
QwtThermo *d_timethermo;
double delay = 1;
class ValueBar: public QWidget
{
public:
ValueBar(Qt:
rientation orientation,
const QString &text, QWidget *parent):
QWidget(parent)
{
d_timelabel = new QLabel(text, this);
d_timethermo = new QwtThermo(this);
d_timethermo->setRange(0,sri);
d_timethermo->setMargin(5);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
d_timelabel->setAlignment(Qt::AlignRight);
d_timethermo->setOrientation(orientation, QwtThermo::LeftScale);
layout->addWidget(d_timethermo, 10, Qt::AlignHCenter);
layout->addWidget(d_timelabel, 0);
}
~ValueBar()
{
}
private:
// QwtThermo *d_thermo;
};
QGroupBox *timeBox;
QVBoxLayout *timeLayout;
Qt:
rientation o1,o2;
class SysInfo : public QFrame
{
public:
SysInfo(QWidget *parent = NULL):
QFrame(parent)
{
#if 1
o1 = Qt::Vertical;
timeBox = new QGroupBox("Time", this);
timeLayout = new QVBoxLayout(timeBox);
timeLayout->setMargin(15);
timeLayout->setSpacing(5);
d_timethermo->setFillColor(QColor("DarkMagenta"));
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setMargin(10);
layout->addWidget(timeBox, 0);
#endif
}
~SysInfo()
{
}
void timerEvent(QTimerEvent *)
{
timeLayout->addWidget(new ValueBar(o1, "Time Factor",timeBox));
d_timethermo->setValue(sri);
cout<<"srii:::::::::::" << sri <<endl;
info->show();
update();
sri = sri+10;
iteration--;
cout<<"THE NUMBER OF ITERATIONS LEFT:"<<iteration<<endl;
if(iteration == 0X0)
{
killTimer(timerId);
}
}
void closeEvent(QCloseEvent *)
{
exit(0);
}
};
int main(int argc , char **argv)
{
QApplication a( argc, argv );
SysInfo *sysinfo = new SysInfo;
sysinfo->setGeometry(705,190,320,170);
info = sysinfo;
timerId = sysinfo->startTimer(delay*1000);
return a.exec();
}
Thanks in Advance.
This post has been edited 3 time(s), it was last edited by srinivasj: 09.05.2008 14:48.
|
|
09.05.2008 11:54 |
|
|
Nicolas SOUCHON
Wizard
  
Registration Date: 27.06.2007
Posts: 726
Level: 29 [?]
Experience: 235,476
Next Level: 242,754
 |
|
you set the range of the thermometer [0..10]
you set values greater than 10 !!!
__________________ Nicolas
|
|
09.05.2008 18:43 |
|
|
srinivasj
Coder

Registration Date: 09.05.2008
Posts: 17
Level: 5 [?]
Experience: 124
Next Level: 173
Thread Starter
 |
|
But every time the timer event is getting called , a new thermometer instance is getting created and new range is being set. U ca find it in this piece of code.
void timerEvent(QTimerEvent *)
{
timeLayout->addWidget(new ValueBar(o1, "Time Factor",timeBox));
d_timethermo->setValue(sri);
cout<<"srii:::::::::::" << sri <<endl;
info->show();
update();
sri = sri+10;
}
here I am incrementing the value of sri by 10.
this incremented value is set as range .
//
d_timethermo->setRange(0,sri);
|
|
10.05.2008 08:53 |
|
|
srinivasj
Coder

Registration Date: 09.05.2008
Posts: 17
Level: 5 [?]
Experience: 124
Next Level: 173
Thread Starter
 |
|
I have done the same thing which you told, but the created thermometer is not getting attached to the time groupBox.
|
|
10.05.2008 09:48 |
|
|
srinivasj
Coder

Registration Date: 09.05.2008
Posts: 17
Level: 5 [?]
Experience: 124
Next Level: 173
Thread Starter
 |
|
Sorry Nicholas.. I did not verify the output correctly.
No I could see the values getting refreshed.
Thanks a lot..
|
|
10.05.2008 09:54 |
|
|
srinivasj
Coder

Registration Date: 09.05.2008
Posts: 17
Level: 5 [?]
Experience: 124
Next Level: 173
Thread Starter
 |
|
I have a doubt .
In the actual actual the range of the thermo has to changed, i.e; I dont know the maximum value that has to be plotted.
the value comes from the /proc/stat file which changes dynamically basing on the load of the cpu.
|
|
10.05.2008 10:12 |
|
|
Nicolas SOUCHON
Wizard
  
Registration Date: 27.06.2007
Posts: 726
Level: 29 [?]
Experience: 235,476
Next Level: 242,754
 |
|
I suppose ve value to be set is in the range [0 .. nbCpu * 100]
set the start range to [0..100],
at each timerEvent
| code: |
1:
2:
3:
4:
5:
|
// pseudo code
while( val > thermo_max ) thermo_max += 100;
thermo_val = val;
|
|
__________________ Nicolas
|
|
10.05.2008 17:40 |
|
|
|
|
|
 |
views today: 9.260 | views yesterday: 17.520 | total views: 10.242.629
Klebekork Shop - Linux Shop - Kontaktanzeigen - Linux Forum -
SMS Gewinnspiel -
Hotels -
Stadtpläne -
Branchenbuch & Stadtplan
|