Fade and scroll effects
From QtCentreWiki
Since Qt 4.6 you can use QPropertyAnimation for these effects.
Warning
This hack relies on private parts of Qt 4. This may or may not work in the future versions of Qt 4. You have been warned.
qeffects_p.h
The following example makes use of qeffects_p.h which can be found in the src/gui/widgets subdir of the Qt 4 source package. On Windows you might be able to simply include "private/qeffects_p.h" but at least on X11 private headers are not installed so you might need to grab it from the source package and include it to the project of yours.
Again, notice what it says in qeffects_p.h:
// W A R N I N G // ------------- // // This file is not part of the Qt API. It exists for the convenience // of qeffects.cpp, qcombobox.cpp, qpopupmenu.cpp and qtooltip.cpp. // This header file may change from version to version without notice, // or even be removed. // // We mean it.
Example
The following example shows a simple popup with scroll and fade effects.
// main.cpp#include <QtGui>#include "qeffects_p.h"class Window : public QMainWindow
{Q_OBJECTpublic:
Window()
{popup = new QWidget(this, Qt::Popup);
popup->setStyleSheet("background: red");
menuBar()->addAction("Scroll", this, SLOT(scrollPopup()));
menuBar()->addAction("Fade", this, SLOT(fadePopup()));
}private slots:
void scrollPopup()
{layoutPopup();
qScrollEffect(popup, QEffects::UpScroll | QEffects::RightScroll);
}void fadePopup()
{layoutPopup();
qFadeEffect(popup);
}private:
void layoutPopup()
{QRect rect = QStyle::alignedRect(layoutDirection(),
Qt::AlignBottom,
QSize(width(), height() / 3),
geometry());
popup->setGeometry(rect);
}QWidget* popup;
};int main(int argc, char* argv[])
{QApplication a(argc, argv);
Window w;
w.show();
return a.exec();
}#include "main.moc"
Both functions take an additional optional argument that sets the duration of the animation in milliseconds. Thus, qScrollEffect(popup, QEffects::UpScroll, 300) would create a scroll up effect that lasts for 300 ms while qFadeEffect(popup, 300) would create a fade effect with the same duration.
jpn 20:05, 18 September 2007 (CEST)

