Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. modifying painter event in a LED class from solid color to Glowing color
Forum Updated to NodeBB v4.3 + New Features

modifying painter event in a LED class from solid color to Glowing color

Scheduled Pinned Locked Moved Solved General and Desktop
glow effectledradialgradientgraphic effects
14 Posts 4 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M mpergand
    29 Mar 2019, 10:53

    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));
    
    V Offline
    V Offline
    VikramSamy
    wrote on 31 Mar 2019, 05:21 last edited by VikramSamy
    #5

    @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...

    1 Reply Last reply
    0
    • V VikramSamy
      31 Mar 2019, 05:08

      @jazzycamel your code can be directly used by any QT version, coz when i try to use it i can compile it, i get the below errors:-

      S:\QTProjects\led_glow_v1\ledglow.cpp:42: error: 'RichMetal' is not a member of 'QGradient'
      innerBezelGrad.setStops(QGradient(QGradient::RichMetal).stops());
      ^
      S:\QTProjects\led_glow_v1\ledglow.cpp:35: error: 'RiskyConcrete' is not a member of 'QGradient'
      outerBezelGrad.setStops(QGradient(QGradient::RiskyConcrete).stops());
      ^

      and i get few of this warning:-
      S:\QTProjects\led_glow_v1\ledglow.h:15: warning: override controls (override/final) only available with -std=c++11 or -std=gnu++11
      QSize minimumSizeHint() const override;
      ^
      anyway i just trying it... see hopefully i can make it compile...

      J Offline
      J Offline
      jazzycamel
      wrote on 1 Apr 2019, 08:33 last edited by
      #6

      @VikramSamy
      What version of Qt are you using?

      1. 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"))
      );
      
      1. You can either add CONFIG += c++11 to your project (.pro) file or remove the word override from the header files to get rid of the warning.

      Hope this helps ;o)

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      V 1 Reply Last reply 1 Apr 2019, 09:51
      2
      • M mpergand
        29 Mar 2019, 10:53

        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));
        
        V Offline
        V Offline
        VikramSamy
        wrote on 1 Apr 2019, 09:38 last edited by VikramSamy 4 Jan 2019, 09:52
        #7

        @mpergand

        ok thanks, i managed to use the code u shared and integrated into my code...
        the output is as follows:-0_1554111160138_led_on.jpg

        and im wana continue to have a ring like smudge effect around the led as in this pic:-

        0_1554111384505_led_on_outside.jpg

        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....

        1 Reply Last reply
        0
        • J jazzycamel
          1 Apr 2019, 08:33

          @VikramSamy
          What version of Qt are you using?

          1. 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"))
          );
          
          1. You can either add CONFIG += c++11 to your project (.pro) file or remove the word override from the header files to get rid of the warning.

          Hope this helps ;o)

          V Offline
          V Offline
          VikramSamy
          wrote on 1 Apr 2019, 09:51 last edited by
          #8

          @jazzycamel said in modifying painter event in a LED class from solid color to Glowing color:

          @VikramSamy
          What version of Qt are you using?

          1. 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"))
          );
          
          1. You can either add CONFIG += c++11 to your project (.pro) file or remove the word override 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...

          J 1 Reply Last reply 1 Apr 2019, 11:06
          0
          • V VikramSamy
            1 Apr 2019, 09:51

            @jazzycamel said in modifying painter event in a LED class from solid color to Glowing color:

            @VikramSamy
            What version of Qt are you using?

            1. 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"))
            );
            
            1. You can either add CONFIG += c++11 to your project (.pro) file or remove the word override 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...

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 1 Apr 2019, 11:06 last edited by
            #9

            @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.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            V 1 Reply Last reply 2 Apr 2019, 03:21
            0
            • M Offline
              M Offline
              mpergand
              wrote on 1 Apr 2019, 12:46 last edited by mpergand 4 Jan 2019, 12:51
              #10

              I think there's something wrong whith QRadialGradient.
              alt text

              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));
              
              J 1 Reply Last reply 2 Apr 2019, 09:15
              0
              • J jsulm
                1 Apr 2019, 11:06

                @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.

                V Offline
                V Offline
                VikramSamy
                wrote on 2 Apr 2019, 03:21 last edited by
                #11

                @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.

                @jazzycamel

                the kit version is Desktop Qt 5.5.1 MinGw 32bits

                1 Reply Last reply
                0
                • M mpergand
                  1 Apr 2019, 12:46

                  I think there's something wrong whith QRadialGradient.
                  alt text

                  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));
                  
                  J Offline
                  J Offline
                  jazzycamel
                  wrote on 2 Apr 2019, 09:15 last edited by
                  #12

                  @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)

                  For the avoidance of doubt:

                  1. All my code samples (C++ or Python) are tested before posting
                  2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
                  M V 2 Replies Last reply 2 Apr 2019, 09:30
                  4
                  • J jazzycamel
                    2 Apr 2019, 09:15

                    @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)

                    M Offline
                    M Offline
                    mpergand
                    wrote on 2 Apr 2019, 09:30 last edited by
                    #13

                    @jazzycamel
                    I was convinced there's something obvious i missed :)
                    Thanks !

                    1 Reply Last reply
                    0
                    • J jazzycamel
                      2 Apr 2019, 09:15

                      @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)

                      V Offline
                      V Offline
                      VikramSamy
                      wrote on 4 Apr 2019, 04:05 last edited by
                      #14

                      @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...

                      1 Reply Last reply
                      0

                      14/14

                      4 Apr 2019, 04:05

                      • Login

                      • Login or register to search.
                      14 out of 14
                      • First post
                        14/14
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved