[Unsolved] QWidget won't Scroll (Qt 4 & 5)

  • Hi everyone! I'm trying to make some messages to scroll. I'm using a QLabel for the message inside a QScrollArea.
    I also used a timer to make it scroll every few ms. The problem is that for some reason it only works on a very specific method of the class that makes it all.

    What I tried to do is to scroll the message to the right far end of the screen in order to make it move to the left like a marquee. But It just ignores the
    @QWidget->scroll(int dx, int dy)

    This is the relevant code of my class:
    #include "boardwindow.h"
    #include "ui_boardwindow.h"

    BoardWindow::BoardWindow(QWidget *parent) : QWidget(parent), ui(new Ui::BoardWindow)
    Scroller= new QTimer(this);
    //connect(Scroller, SIGNAL(timeout()), this, SLOT(ScrollText()));

    delete ui;

    void BoardWindow::Initialize()
    QDesktopWidget test;

    // Ventana sin borde ni botones. Y por encima de cualquier otra
    setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
    // En que resolucion estamos?
    DesktopRes= test.availableGeometry(test.primaryScreen());
    // Adaptemos la ventana para la resolucion actual!
    resize(DesktopRes.width(), height());
    // Finalmente, vamos a mover la ventana al borde inferior del monitor
    move(0, DesktopRes.height()-40);


    // Esta es la funcion que animara el texto
    void BoardWindow::ScrollText()
    /* MessagePosition= ui->ScrollingText->pos();

    // Ya salio de pantalla?
    if (MessagePosition.x()<=-ui->ScrollingText->width())
        ui->ScrollAreaWidget->scroll(-5, 0);


    /* Esta funcion cargara un nuevo texo de Messages cuando

    • el anterior haya salido totalmente de la pantalla
      void BoardWindow::NextMessage()
      ui->ScrollAreaWidget->scroll(500, 0);
      qDebug("AHORA EN: %d", ui->ScrollingText->pos().x());
      ui->ScrollingText->setText("Ola ke ase");
      ui->ScrollAreaWidget->scroll(DesktopRes.width(), 0);*/

    It doesn't work anywhere else but on ScrollText()

    Does anyone knows why? I've read the QWidget reference for scroll(int dx, int dy) and I haven't seen any precondition or anything that prevents it to work.

  • Update:

    The only way it scrolls is with QTimer. Every timeout() signal it makes the QWidget to scroll in the desired direction. But why?

    The same behaviour happens with Qt 4.8.

    Any thoughts?

  • You could use the scrollable text visualizer QTextEdit in the first place instead of re-building something like this class on your own with a QLabel in a scroll area.

  • I'll take a look at your idea since I'm having some annoying issues with my approach. Thanks msue.

    But this keeps the question on the table, why scroll(int dx, int dy) doesn't work everywhere?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.