Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting a widget to slowly roll down the screen

Getting a widget to slowly roll down the screen

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MichaelStein
    wrote on last edited by
    #1

    Hi Everyone,

    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:

    file header.h
    @#ifndef HEADER_H
    #define HEADER_H

    #include <QtGui>

    class Widget : public QWidget
    {
    public:
    Widget(QWidget *parent = 0) : QWidget(parent)
    {
    new QPushButton("Widget", this);
    }
    };

    class Window : public QDialog
    {
    Q_OBJECT
    public:
    Window()
    {
    QPushButton *button = new QPushButton("Button", this);
    widget = new Widget(this);
    widget->move(20, 30);
    connect(button, SIGNAL(clicked()), this, SLOT(rollDownScreen()));
    }

    public slots:
    void rollDownScreen()
    {
    widget->scroll(0, 1);

    }
    

    private:
    Widget *widget;
    };

    #endif // HEADER_H
    @

    file main.cpp
    @#include "header.h"
    #include <QGraphicsScene>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Window w;
    w.show();
    return a.exec();
    }
    @

    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:
    @public slots:
    void rollDownScreen()
    {
    index =0;
    while(index < 20)
    {
    index++;
    widget->scroll(0, index);
    }
    }

    private:
    Widget *widget;
    int index;

    };@

    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.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by SGaist
        #3

        Hi,

        To add to Chris Kawa, you can also use a QPropertyAnimation.

        [edit: fixed link SGaist]

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • M Offline
          M Offline
          MichaelStein
          wrote on last edited by
          #4

          Wow, thank you - both of you!

          1 Reply Last reply
          -1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved