Fade and scroll effects
Since Qt 4.6 you can use QPropertyAnimation for these effects.
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.
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.
The following example shows a simple popup with scroll and fade effects.
class Window : public QMainWindow
popup = new QWidget(this, Qt::Popup);
menuBar()->addAction("Scroll", this, SLOT(scrollPopup()));
menuBar()->addAction("Fade", this, SLOT(fadePopup()));
qScrollEffect(popup, QEffects::UpScroll | QEffects::RightScroll);
QRect rect = QStyle::alignedRect(layoutDirection(),
QSize(width(), height() / 3),
int main(int argc, char* argv)
QApplication a(argc, argv);
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)