Blinking button using stylesheets
-
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 ? -
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);
}
}
}
}
@ -
Ok, works fine ! Thanks !
-
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 ?