Need help associating values to a widget.
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
Re: Need help associating values to a widget.
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.
Re: Need help associating values to a widget.
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.
Re: Need help associating values to a widget.
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?
Re: Need help associating values to a widget.