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. Blinking Custom WIdget problem ...
Forum Updated to NodeBB v4.3 + New Features

Blinking Custom WIdget problem ...

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.4k 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.
  • gfxxG Offline
    gfxxG Offline
    gfxx
    wrote on last edited by
    #1

    I try to make a custom widget .. a blinking Led utilizing in multiple place of my guy .. all works .. so I add a timer and some void for make possible choice if blinking or not when I use it in my code .... works but these cause some malfunctions when multiple widget blink ... I not see my error ... Precisely: all works when only one widget blink, when blink more than one and other is set to not blinking there are some confusion in time event so certain blinking widget blink other blinking widget no. Other blinking widget set to work in non-blinking mode works correctly .... the code:

    #ifndef QRECTLEDY_H
    #define QRECTLEDY_H
    
    #include <QLabel>
    #include <QPixmap>
    #include <QTimer>
    
    class QRectLedy : public QLabel
    {
        Q_OBJECT
    public:
        QRectLedy(QWidget *parent = 0);
    
    public slots:
    
        void RLYexchange(bool Rly, bool RlyPass);
        void RLYsetFlashing(bool blink);
        bool blink();
        void RLYsetState(bool state);
        bool state();
        void RLYsetFlashRate(int blinkRate);
        int blinkRate();
    
    private slots:
    
        void RYon();
        void RYoff();
        void RLYexchangeBlink();
        //void RLYestinguish();
    
    
    private:
        QTimer* blinkTimer;
        QPixmap onPixmap, offPixmap;
        bool m_blink;
        bool m_state;
        int m_blinkRate;
    
    
    
    };
    
    #endif // QRECTLEDY_H
    
    
    
    
    /**** header end ****************************************************/
    
    
    #include "qrectledy.h"
    #include <QTimer>
    #include <QDebug>
    
    
    bool indexB = false;
    
    QRectLedy::QRectLedy(QWidget *parent)
        : QLabel(parent), onPixmap("/home/k/res/rect_led_yellow_on_130.png"), offPixmap("/home/k/rect_led_yellow_off_130.png")
    {
        setPixmap(offPixmap);
        blinkTimer = new QTimer();
        blinkTimer->start(800);
        connect(blinkTimer, SIGNAL(timeout()), this, SLOT(RLYexchangeBlink()));
    
    
    
    }
    
    void QRectLedy::RLYexchange(bool Rly, bool RlyPass)
    {
        if (RlyPass && Rly && !m_blink) {
            RYon();
        }
        else if(RlyPass && !Rly && !m_blink) {
            RYoff();
        }
        else if (!RlyPass && !Rly && m_blink && !indexB) {
            RYon();
            indexB = true;
        }
        else if (!RlyPass && !Rly && m_blink && indexB) {
            RYoff();
            indexB = false;
        }
        else{
            RYoff();
            indexB = false;
        }
    }
    
    void QRectLedy::RLYexchangeBlink()
    {
        if(m_blink){
           RLYexchange(false, false);
        }
        else{
           RLYexchange(m_state, true);
        }
    }
    
    void QRectLedy::RLYsetFlashRate(int blinkRate)
    {
        m_blinkRate = blinkRate;
    }
    
    void QRectLedy::RLYsetFlashing(bool blink)
    {
        m_blink = blink;
    }
    
    void QRectLedy::RLYsetState(bool state)
    {
        m_state = state;
    }
    
    bool QRectLedy::blink()
    {
        return m_blink;
    }
    
    bool QRectLedy::state()
    {
        return m_state;
    }
    
    int QRectLedy::blinkRate()
    {
        return m_blinkRate;
    }
    
    
    
    void QRectLedy::RYoff()
    {
        setPixmap(offPixmap);
    }
    
    void QRectLedy::RYon()
    {
        setPixmap(onPixmap);
    }
    
    

    giorgio

    bkt

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      its due to your GLOBAL variable
      bool indexB = false;

      it should be part of the class as else each blinking will make problem for others as
      the states are mixed.
      Moved to the class and all should be good :)

      1 Reply Last reply
      1
      • gfxxG Offline
        gfxxG Offline
        gfxx
        wrote on last edited by
        #3

        Re: Blinking Custom WIdget problem ...

        Very thanks ... so I declare in header as :

        private:
        
        bool = indexB = false; /***** because C11++ ***********/
        

        All works fine.

        Giorgio

        bkt

        1 Reply Last reply
        1

        • Login

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