My blog has been moved to

Monday, December 19, 2005

Pulsating Effect for QToolTip

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 = 0;

    foreach(QWidget *widget, QApplication::allWidgets())
        tipLabel = qobject_cast<QLabel*>(widget);
    int k = (index>7) ? 14-index : index;
    index += (index<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()));

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.

1 comment:

_anonymous_blogger_ said...

Excellent !!!!! it truly rocks, i cant wait having tons of blinking items on the desktop, looks like kde4 will be really animated thx!! lol :-)