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 button using stylesheets

Blinking button using stylesheets

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 14.6k Views
  • 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.
  • F Offline
    F Offline
    f.vanalmetelevic.com
    wrote on 13 Sept 2010, 13:23 last edited by
    #1

    with qt-creator's designer, I created a round button. Therefor, I adjusted the style sheet of the button like this :

    @QPushButton {
    background-color: red (170,0,0);
    background-image: url(:/Images/alarmButtonReflection.png) ;
    background-repeat: none;
    background-position: top center;
    background-origin: content;
    padding: 3px;
    border-style: solid;
    border-width: 3px;
    border-color: red (120,0,0);
    border-radius: 40px;
    }

    QPushButton:pressed {
    background-color: rgb(255,0,0);
    background-image: url(:/Images/alarmButtonReflection.png) ;
    background-repeat: none;
    background-position: top center;
    background-origin: content;
    }
    @

    This works fine. Now, I would like to make the button "flash" with a certain interval. I can do this by changing the stylesheet within my program : button->setStyleSheet ("background-color: red"); However, the other style-settings of the button are not maintained when doing this (e.g. the button becomes rectangular again). Is there a way, to change one style-sheet item without affecting the others ? I could have all the style-sheet settings within my setStyleSheet command, but I don't think this is the way to do it...
    Are there any alternative methods to do the flashing of the button ?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luca
      wrote on 13 Sept 2010, 14:25 last edited by
      #2

      Hi, in an application I've done this way:

      css file:
      @
      PulsanteLampeggiante {
      border: 6px solid rgb(200,10,10);
      border-radius: 5px;
      color: black;
      }
      PulsanteLampeggiante[lampeggio="true"] {
      border: 6px solid rgb(200,10,10);
      border-radius: 5px;
      color: rgb(255,0,0);
      }
      @

      where PulsanteLampeggiante is derived from QPushButton .

      @
      void PulsanteLampeggiante::timerEvent(QTimerEvent *e)
      {
      if(e->timerId() == lampeggioTimer)
      {
      if(this->isEnabled())
      {
      if(statoAttuale == 0)
      {
      statoAttuale= 1;
      this->setProperty("lampeggio", true);
      }
      else if(statoAttuale == 1)
      {
      statoAttuale = 0;
      this->setProperty("lampeggio", false);
      }
      style()->unpolish(this);
      style()->polish(this);
      }
      else //se non รจ abilitato non lampeggio
      {
      if(statoAttuale!=0)
      {
      statoAttuale=0;
      this->setProperty("lampeggio", false);
      style()->unpolish(this);
      style()->polish(this);
      }
      }
      }
      }
      @

      1 Reply Last reply
      0
      • F Offline
        F Offline
        f.vanalmetelevic.com
        wrote on 14 Sept 2010, 07:24 last edited by
        #3

        Ok, works fine ! Thanks !

        1 Reply Last reply
        0
        • L Offline
          L Offline
          luca
          wrote on 14 Sept 2010, 07:28 last edited by
          #4

          The only problem I find is that this way require more CPU and I couldn't use this in small embedded linux.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            f.vanalmetelevic.com
            wrote on 14 Sept 2010, 07:50 last edited by
            #5

            Thanks for this tip. That could become a problem for me too... Up till now, I was developing on a Linux host. But the final target of the software is an embedded device. So, it might be a good idea to continue looking for another solution...

            Anyone any other ideas ?

            1 Reply Last reply
            0

            1/5

            13 Sept 2010, 13:23

            • Login

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