PDA

View Full Version : Need help associating values to a widget.



Fouad Hanoun
16th December 2015, 16:55
Hello,
I have a project for uni and i want to associate values (floats) to a visual widget.

Let's say it's in percentage, where 0% is totally blue and 100% is totally green, what's in between varies between blue and green.

It's a matrix and i want to associate it's values to create a blue square that starts to turn green with time, the c++ code is ready but i don't know much about GUI.

Any idea how to it? what should i use to be able to form a square with my values and associate them to a colour?

Thanks a lot

ChrisW67
16th December 2015, 21:01
If you can create a QPixmap of the correct size containing your coloured square (QPainter) then you can simply display it in a QLabel. Once you can do that then animating a colour change becomes possible.

d_stranz
16th December 2015, 21:01
Probably the easiest would be to create a QWidget, and implement the paintEvent() to fill the square with the current color. You create a QTimer to cycle through your colors. To change the current color, you would implement a slot connected to the timer's timeout signal. In this slot, you set the current color based on where you are in the color cycle, then call repaint() on the widget to trigger a new paint event.

Or use ChrisW67's alternative approach.

Fouad Hanoun
17th December 2015, 10:51
well i don't want to change the colour using paint event but i wan t to link each of values which are 100 different value to shades of blue/green. can it be done?

d_stranz
17th December 2015, 16:09
QGradient and QLinearGradient might help.