PDA

View Full Version : Using QLabel to increase/decrease a Status Bar



JonSim
30th January 2016, 04:31
11671

Attached is a pic of my StatusBar using QLabel.
I would like to know how to write the code for increasing or decreasing the white bar inside of the Status Bar. It would be best if you can give me an example of the coding needed to be written.

Condition:

The white bar will increase by one bar at a time whenever a Increase button is pressed.
The white bar will decrease by one bar at a time whenever a Decrease button is pressed.
All the Statusbar and the 4 white bars are design using QLabel.
There are 2 QPushbutton to select the increase or decrease functions.

anda_skoa
30th January 2016, 11:40
If you want to do this with a QLabel, you will have to generate a pixmap every time its content should change and then set the new pixmap.

However, this looks like a situation where you would want to have a custom widget, that has exactly that visualization.

- derive from QWidget
- have a member variable that stores how many sections are filled
- have two slots, one that increments that value and one that decrements it
- implement paintEvent() to draw that for and as many sections filled as the member indicates

Cheers,
_

JonSim
31st January 2016, 13:46
Hi thank for the reply.
But do you know how can i go about doing it? Not so sure about doing it.
Thank you

anda_skoa
31st January 2016, 14:18
Which of the steps have you completed already?

Cheers,
_

JonSim
11th February 2016, 02:26
Thanks for the help. I have managed to complete it thanks to my mentor