Important: Please read the Qt Code of Conduct -

Glitched scroll of QScrollArea

  • 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) :
        ui(new Ui::MainWindow) {
        QVBoxLayout *mainLayout = new QVBoxLayout();
        for(int i = 0; i < 60; i++) {
            auto *w = createWidget(i);
        QWidget *mainWidget = new QWidget();
        QScrollArea *scrollArea  = new QScrollArea();
    MainWindow::~MainWindow() {
        delete ui;
    QWidget* createWidget(int id) {
        auto w = new QWidget();
        auto lay = new QVBoxLayout(w);
        auto ed = new QPlainTextEdit();
        if (id % 10 == 0)
        return w;

  • Lifetime Qt Champion


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

  • 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.

  • Lifetime Qt Champion

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

  • Yes, here it is.


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

  • Lifetime Qt Champion

    A bit like a python notebook ?

  • Yeah, something like this.

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

  • Should I report this as a bug?

  • Lifetime Qt Champion

    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.

Log in to reply