modifying painter event in a LED class from solid color to Glowing color
-
@mpergand said in modifying painter event in a LED class from solid color to Glowing color:
Have a look at QPainterPath and QRadialgradient:
QPainterPath path; path.addEllipse(rectangle); QRadialGradient gradient(rectangle.center(), m_diameter, rectangle.center()); gradient.setColorAt(0, m_on_color); gradient.setColorAt(1, Qt::transparent); painter.fillPath(path,QBrush(gradient));
hi can help give some tips on how can i can integrate this into my code previously which i shared here, meaning i still use the rectangle which i built and this code suppose will add another layer on my rectangle..i try few ways to add your code but finally i just get the same solid colors which is used in my code... can u give some simple explanation on how use it and integrate it in my code... anyway timebeing il still on the process of trying it...
-
@VikramSamy
What version of Qt are you using?- If the named gradients aren't available in your Qt version then you can construct your own in the same way I do for the main colour as follows:
//outerBezelGrad.setStops(QGradient(QGradient::RiskyConcrete).stops()); outerBezelGrad.setStops( QGradientStops() << QGradientStop(0, QColor("#c4c5c7")) << QGradientStop(0.52, QColor("#dcdddf")) << QGradientStop(1, QColor("#ebebeb")) ); ... //innerBezelGrad.setStops(QGradient(QGradient::RichMetal).stops()); innerBezelGrad.setStops( QGradientStops() << QGradientStop(0, QColor("#d7d2cc")) << QGradientStop(1, QColor("#304352")) );
- You can either add
CONFIG += c++11
to your project (.pro) file or remove the wordoverride
from the header files to get rid of the warning.
Hope this helps ;o)
-
ok thanks, i managed to use the code u shared and integrated into my code...
the output is as follows:-and im wana continue to have a ring like smudge effect around the led as in this pic:-
i did find another code from google and trying to use it currently, but if u know any easier modifications to be made in your code that u shared to have this similar effects, hopefully u can modify it....
-
@jazzycamel said in modifying painter event in a LED class from solid color to Glowing color:
@VikramSamy
What version of Qt are you using?- If the named gradients aren't available in your Qt version then you can construct your own in the same way I do for the main colour as follows:
//outerBezelGrad.setStops(QGradient(QGradient::RiskyConcrete).stops()); outerBezelGrad.setStops( QGradientStops() << QGradientStop(0, QColor("#c4c5c7")) << QGradientStop(0.52, QColor("#dcdddf")) << QGradientStop(1, QColor("#ebebeb")) ); ... //innerBezelGrad.setStops(QGradient(QGradient::RichMetal).stops()); innerBezelGrad.setStops( QGradientStops() << QGradientStop(0, QColor("#d7d2cc")) << QGradientStop(1, QColor("#304352")) );
- You can either add
CONFIG += c++11
to your project (.pro) file or remove the wordoverride
from the header files to get rid of the warning.
Hope this helps ;o)
im using this version:-
Qt Creator 3.5.1 (opensource)
Based on Qt 5.5.1 (MSVC 2013, 32 bit)ok thank you and il try to compile again...
-
@VikramSamy said in modifying painter event in a LED class from solid color to Glowing color:
Qt Creator 3.5.1 (opensource)
Based on Qt 5.5.1 (MSVC 2013, 32 bit)This is the Qt version used to build QtCreator. Check your Kit to see which Qt version you're really using.
-
I think there's something wrong whith QRadialGradient.
With radial, the end stop color is wrong. (should be transparent like with Linear)
Code for Radial:QRadialGradient gradient1(rec.center(), rec.width()); gradient1.setColorAt(.0,Qt::red); gradient1.setColorAt(.9, Qt::transparent); painter.fillPath(path1,QBrush(gradient1));
Code for Linear:
QLinearGradient gradient2(rec.topRight(),rec.bottomRight()); gradient2.setColorAt(0, Qt::red); gradient2.setColorAt(.9, Qt::transparent); painter.fillPath(path1,QBrush(gradient2));
-
@jsulm said in modifying painter event in a LED class from solid color to Glowing color:
@VikramSamy said in modifying painter event in a LED class from solid color to Glowing color:
Qt Creator 3.5.1 (opensource)
Based on Qt 5.5.1 (MSVC 2013, 32 bit)This is the Qt version used to build QtCreator. Check your Kit to see which Qt version you're really using.
the kit version is Desktop Qt 5.5.1 MinGw 32bits
-
@mpergand said in modifying painter event in a LED class from solid color to Glowing color:
QRadialGradient gradient1(rec.center(), rec.width());
gradient1.setColorAt(.0,Qt::red);
gradient1.setColorAt(.9, Qt::transparent);
painter.fillPath(path1,QBrush(gradient1));There is nothing wrong with QRadialGradient, just the way you are using it. When you construct the QRadialGradient, the first argument is the center point and the second argument is the radius not the diameter you want. If you change your first line to the following you will get the effect you expect:
... QRadialGradient gradient1(rec.center(), rec.width()/2); ...
Hope this clears things up ;o)
-
@jazzycamel
I was convinced there's something obvious i missed :)
Thanks ! -
@jazzycamel said in modifying painter event in a LED class from solid color to Glowing color:
@mpergand said in modifying painter event in a LED class from solid color to Glowing color:
QRadialGradient gradient1(rec.center(), rec.width());
gradient1.setColorAt(.0,Qt::red);
gradient1.setColorAt(.9, Qt::transparent);
painter.fillPath(path1,QBrush(gradient1));There is nothing wrong with QRadialGradient, just the way you are using it. When you construct the QRadialGradient, the first argument is the center point and the second argument is the radius not the diameter you want. If you change your first line to the following you will get the effect you expect:
... QRadialGradient gradient1(rec.center(), rec.width()/2); ...
Hope this clears things up ;o)
yup got the effects....thanks...