[SOLVED] Howto make a warning sign blinking
-
Hi,
I would like to make a warning sign blinking on my GUI if the user presses a start button. Signal and slots I do already know well so I could take the event from the button.
But how I could make a warning sign blinking? Can you tell me what should I study (custom widgets, graphics view, ...)?
I would also be intrested for tutorials to this subject?
Thanks
-
Hi,
Where do you need that warning? Should the button blink, should a label or picture blink??
It sounds to me you need to inherit from the widget you need blinking and then setup a QTimer in that class that will be started when the button is pressed (event). Then in the timer event change the colour or any other option you need blinking. -
It's a picture that should blink:
!https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQ-0spNMNPd9m4_xPMjtDLI5UzyyD2pEXXqgeUG8bI__4DuqvA-zg! -
Hi,
a possible way is to subclass QGraphicsPixmapItem and animate the opacity property.
@
class AnimatedGraphicsItem : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
Q_PROPERTY(double opacity READ opacity WRITE setOpacity)public:
AnimatedGraphicsItem(QObject *parent = 0);.....
};
void SomeClass::InitGraphicsItem()
{
m_MyAnimatedGraphicsItem = new AnimatedGraphicsItem();
QGraphicsScene *m_scene = new QGraphicsScene();
MyGraphicsView.setScene(m_scene);QPixmap p; p.load(QString::fromStdString("SomeImage")); m_MyAnimatedGraphicsItem->setPixmap(p); m_scene.addItem(m_MyAnimatedGraphicsItem);
}
void SomeClass::DoBlink()
{
m_statusAni = new QPropertyAnimation(m_MyAnimatedGraphicsItem,"opacity");
m_statusAni->setDuration(1600);
m_statusAni->setStartValue(0.0);
m_statusAni->setKeyValueAt(0.5,1.0);
m_statusAni->setEndValue(0.0);
m_statusAni->setEasingCurve(QEasingCurve::InCurve);
m_statusAni->setLoopCount(-1);
m_statusAni->start(QPropertyAnimation::DeleteWhenStopped)
}
@Hope that helps
-
Another way would be to just make the "blinking" animation in a .gif. This gives you the most freedom as to what the blinking looks like.
Then all you'd need to do to show it is:
@
auto movie = new QMovie("path/to/animation/file.gif");
auto label = new QLabel();label->setMovie(movie);
movie->start();
@ -
Or inherit from QLabel and in a timerEvent change the border picture?? Then generate two pictures, warning on/off and change between them. The other options are more fancy must say!!
-
Thanks all for your suggestions.
After trying to implement the suggestion from sw0ce. I finaly realized the suggestion from Jeroentje@ho..