ariya.io About Collections Archives

Pulsating Effect for QToolTip

1 min read

About ten months ago, I played around with the idea of pulsating effect in QToolTip. Basically, the background color is changed quickly to series of some colors. See this Flash animation. The actual effect is of course much smoother than what is shown in this Flash demo.

Unfortunately that trick does not work anymore with the new Qt 4 as you can’t change QToolTip’s palette. However, I am able to get the solution: find the QTipLabel and then apply the same crime.

void MyWindow::beat()
{
  static QPointer<qlabel> tipLabel;
  static int index = ;
 
  if(!tipLabel)
    foreach(QWidget *widget, QApplication::allWidgets())
      if(widget->inherits("QTipLabel"))
        tipLabel = qobject_cast</qlabel><qlabel>(widget);
 
  if(tipLabel)
  {
    int k = (index>7) ? 14-index : index;
    index += (index&lt;14) ? 1 : -14;
 
    QColor c = QColor( 255, 128+k*16, k*20 );
    QPalette pal = tipLabel->palette();
    pal.setColor( QPalette::Background, c );
    tipLabel->setPalette( pal );
  }
 
  QTimer::singleShot(tipLabel? 100 : 1000, this, SLOT(beat()));
}
</qlabel>

This is again a dirty hack, but it works as long as your program does not create its own QTipLabel and QToolTip implementation won’t be radically changed.

♡ this article? Explore more, check the archives, or follow me Twitter.

Share this on Twitter Facebook Google+

comments powered by Disqus