Getting a widget to slowly roll down the screen
I need to have a widget slowly roll down the screen (kind of like a screen saver). Additionally once it reaches the bottom of the screen, it need it to then slowly roll down from the top of the screen. This process should be repeated as long as the screen is idle.
So far I have the following:
class Widget : public QWidget
Widget(QWidget *parent = 0) : QWidget(parent)
new QPushButton("Widget", this);
class Window : public QDialog
QPushButton *button = new QPushButton("Button", this);
widget = new Widget(this);
connect(button, SIGNAL(clicked()), this, SLOT(rollDownScreen()));
#endif // HEADER_H
int main(int argc, char *argv)
QApplication a(argc, argv);
The problem is that I need to keep pressing the button to keep the widget rolling down off the screen. The other problem is that I don't know how to get the widget to reappear and keep rolling from the top of the screen.
So I thought to change the slot() function to do this as follows:
while(index < 20)
However, this just makes the widget jump out of the screen too fast.
If anyone can help, I would be very grateful.
PS. using Qt4.7.
Instead of loop or a button use "a timer":http://qt-project.org/doc/qt-4.8/qobject.html#startTimer with whatever interval you want.
In the timerEvent set the widget position with move() (don't use scroll() for that).
The position should be taken modulo ( % ) screen height. You can get it for example with "QDesktopWidget::screenGeometry":http://qt-project.org/doc/qt-4.8/qdesktopwidget.html#screenGeometry
To add to Chris Kawa, you can also use a QPropertyAnimation.
[edit: fixed link SGaist]
Wow, thank you - both of you!