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) : 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; }
-
Hi,
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. -
Can you show a sketch or an image of what you are trying to achieve ?
-
A bit like a python notebook ?
-
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.