QScrollArea issue on Android
-
It seems to me that QScrollArea doesn't update the screen properly on Android (Qt 6.7.2, Samsung Galaxy S21). When I scroll, the top part and the left part of the screen remains the same. When I rotate the device, it recovers, but in general, I cannot publish any app with this behaviour. Is it a Qt issue or a Samsung issue? How can I fix it? I just wrote a minimalistic app to demonstrate the issue. It works fine on any other platform but Android. This is the original screen before I scroll:
.... and after:
The source code:
#include "mainwidget.h" #include <QScrollArea> #include <QVBoxLayout> #include <QLabel> MainWidget::MainWidget(QWidget *parent) : QWidget(parent) { QScrollArea *scroll = new QScrollArea(); QVBoxLayout *outerLayout = new QVBoxLayout(); QVBoxLayout *innerLayout = new QVBoxLayout(); QWidget * innerWidget = new QWidget(); innerWidget->setLayout(innerLayout); for (int i = 0; i < 30; i++) { auto mlabel = new QLabel(QString::number(i)); innerLayout->addWidget(mlabel); } scroll->setWidget(innerWidget); outerLayout->addWidget(scroll); setLayout(outerLayout); } MainWidget::~MainWidget() { }
Any help is very appreciated. Thanks!
-
Android screen redraws are really fucked up in C++,
I have not tried QML myself but read other who has switched to QML. I myself have no interest of switching to QML but if it helps you then.Example of bugreport:
https://bugreports.qt.io/browse/QTBUG-128794/Martin
-
no, Qt Widgets has just never been intended to be used on mobile devices.
If you want your app to run on android or ios devices, you need Qt Quick / QML !!! -
@ankou29666
I didn't know it has never been intended to be used on mobile, but my app with around 7.000 lines of C++ QWidget code runs just fine on iOS. It cannot be a giant coincidence, at Qt they must have some intention to make it work. I would much rather solve the scroll issue on Android instead of rewriting the whole app in Qt Quick. But yes, most probably you are right about Qt Quick being a better fit for mobile. It is already on my list to learn it, thanks for the reminder. -
as far as I know the Qt Company has always recommended Qt Quick for mobile devices. According to this video, Qt Quick and QML were created because Qt Widgets didn't suit the job of mobile UI.
so your code may work on iOS, I seriously doubt it is intended to.As far as I know, the intention of the Qt Company, that they've had for long now, is to stop developing new features with Qt Widgets, those new features are available with Qt Quick only. Just have a look at recent modules like Qt Location : it does have UI elements to display maps in Qt Quick / QML, but there's obviously none in Qt Widgets. There's only non UI classes in C++.
By the way, there's a popular tool for UI mockup named Figma that allows you to design your UI, and Qt offers a bridge (which is a Figma plugin, not a Qt Design Studio plugin) that allows you to import your design into Design Studio. (Or use Design Studio directly ? yours to see.)
I'm currently looking at it. It seems really nice.