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. Glitched scroll of QScrollArea
Forum Updated to NodeBB v4.3 + New Features

Glitched scroll of QScrollArea

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 2.0k 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.
  • X Offline
    X Offline
    Xanx
    wrote on last edited by
    #1

    Hello there.
    I've found a difference in behaviour of QScrollArea under Mac and under Windows (I haven't tested this on Linux).

    I have a QScrollArea that contains several QWidget's each of which contains a QVBoxLayout, that contains a single QPlainTextEdit. I'm trying to scroll the QScrollArea. When the mouse cursor is above the QScrollArea itself everything is fine, the scroll is smooth. When I'm using Windows and the scroll is above a QPlainTextEdit everything is fine too, scroll is still smooth. When I'm using Mac and the cursor is above a QPlainTextEdit the scroll glitches. When the cursor leaves a QPlainTextEdit, it becomes smooth, but when it enters an edit, it glitches again.

    It seems that under Mac the edit tries to handle scroll events itself. What can I do to enable smooth scrolling on Mac too?

    I captured a short video that illustrates the problem.

    Here is my code (used to capture the video):

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include <QVBoxLayout>
    #include <QScrollArea>
    #include <QPlainTextEdit>
    #include <QWidget>
    
    QWidget* createWidget(int id);
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow) {
        ui->setupUi(this);
    
        QVBoxLayout *mainLayout = new QVBoxLayout();
    
    
        for(int i = 0; i < 60; i++) {
            auto *w = createWidget(i);
            mainLayout->addWidget(w);
        }
    
        mainLayout->addStretch();
    
        QWidget *mainWidget = new QWidget();
        mainWidget->setLayout(mainLayout);
    
        QScrollArea *scrollArea  = new QScrollArea();
        scrollArea->setWidgetResizable(true);
        scrollArea->setWidget(mainWidget);
    
        setCentralWidget(scrollArea);
    }
    
    MainWindow::~MainWindow() {
        delete ui;
    }
    
    QWidget* createWidget(int id) {
        auto w = new QWidget();
        auto lay = new QVBoxLayout(w);
        auto ed = new QPlainTextEdit();
        lay->addWidget(ed);
        lay->setMargin(0);
        lay->setSpacing(0);
    
        ed->setPlainText(QString("%1").arg(id));
        if (id % 10 == 0)
            ed->setMinimumHeight(150);
        return w;
    }
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Out of curiosity, why so many layers ? Why not have only one layout with all your QPlainTextEdit in it ?

      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
      0
      • X Offline
        X Offline
        Xanx
        wrote on last edited by
        #3

        why so many layers ?

        I need an ability to dynamically create as many edits as needed.
        I need a widget that stores text blocks, each of which is isolated from others. That means, when I edit a block all others must stay untouched, for example, when I press Backspace and keep it pressed, only the current block must be erased, the previous one must be preserved. Each block can contain not only text, but also other widgets (or in the simplest case - only images), that is why I could not add just edits, without wrapping images. Aforementioned images visualize user input in edits, so logically it should be a separate entity, not a part of the edit's content.

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

          Can you show a sketch or an image of what you are trying to achieve ?

          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
          0
          • X Offline
            X Offline
            Xanx
            wrote on last edited by
            #5

            Yes, here it is.

            0_1505209712084_Untitled.png

            These blocks (blue border) are created dynamically and as much as the user needs, so I need a QScrollArea to wrap them all.

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

              A bit like a python notebook ?

              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
              0
              • X Offline
                X Offline
                Xanx
                wrote on last edited by
                #7

                Yeah, something like this.

                1 Reply Last reply
                0
                • X Offline
                  X Offline
                  Xanx
                  wrote on last edited by
                  #8

                  That's strange, on Windows it works fine, and the problem exists on OS X. Unfortunately I could not test the code on Linux.

                  1 Reply Last reply
                  0
                  • X Offline
                    X Offline
                    Xanx
                    wrote on last edited by
                    #9

                    Should I report this as a bug?

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

                      Tested on Linux and it doesn't suffer from that.

                      Before opening a bug, please take the time to search for something similar. If you have to open a new report (or you find one already that doesn't provide a MCE), turn your code sample into a fully compilable minimal example and add it to the report.

                      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
                      0

                      • Login

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