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. [Unsolved] QWidget won't Scroll (Qt 4 & 5)
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.3k 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.
  • B Offline
    B Offline
    BlastDV
    wrote on last edited by
    #1

    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)
    @
    method.

    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)
    {
    ui->setupUi(this);
    Scroller= new QTimer(this);
    //connect(Scroller, SIGNAL(timeout()), this, SLOT(ScrollText()));
    }

    BoardWindow::~BoardWindow()
    {
    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);
    
    NextMessage();
    
    Scroller->start(50);
    

    }

    // 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())
        NextMessage();
    else
        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());
      /
      qDebug("next");
      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.

    (8) Just live your life blind like me (8)

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BlastDV
      wrote on last edited by
      #2

      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?

      (8) Just live your life blind like me (8)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        msue
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BlastDV
          wrote on last edited by
          #4

          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?

          (8) Just live your life blind like me (8)

          1 Reply Last reply
          0

          • Login

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