SignalMeter

I wanted to write a piece of C++ code to brush up my programming skill so I decided to develop a widget for the Qt programming environment. I decided to code an S meter. its possible to change the type of meter to anything without to much effort. The slider has been added just for demonstration. It is part of the application and not the Signal Meter widget.

Software Description

The class is called SignalMeter it contains the functions to draw the meter and update its value. The functions contained in the class are:-

void drawMeterBackground(QPainter *painter, QRect *rect,QBrush *brush);
void drawMeterScale(QPainter *painter,QRect *arkrect,QPen *pen);
void drawMeterNeedle(QPainter *painter,QRect *rect,QRect *arkrect,QPen *pen,float needlevalue);
void drawMeterName(QPainter *painter,QPen *pen,QRect *rect);
void drawCase(QPainter *painter,QRect *rect,QPen *pen,QBrush *brush);
void updateNeddleValue(float value);
void paintEvent(QPaintEvent *e);
void setSize(int sizeX,int sizeY);

As you can see the function names are self explanatory. The paintEvent updates the screen when any changes are made. To use the class in your own project you need to add the SignalMeter class to your project folder. There are two ways you can add the widget. You can declare  a new SignalMeter instance add the widget using the code :-

smeter = new SignalMeter(this);
ui->gridLayout->addWidget(smeter);

The second method using Qt Creator is to use the design editor and placing a widget on to your design and using the promote option to promote the SignalMeter class to the widget you placed. To use the promote option highlight the widget right click over it and select promote then enter the class name and click promote. Now the Signal Meter widget its attached to your project. It will not show until you run the project. If you get any errors make sure the SignalMeter class is compiled and has generated an SingnaMeter.o object file.

The source code can be download along with the complied program which was compiled as a 32bit application and checked on Windows XP and 7. To run the demo unzip the files into a directory and double click the .exe file.

If you have any questions please Contact Me and I will try to answer them for you.

Example of Signal Meter use.

Signal Meter Source Code Download

Meter Widget Demo Source Code Download

Meter Widget Demo Executeable Download