QWidget initial resize event size is wrong on Android
-
When starting the program, the widget is set to Qt::WindowMaximized. Running on desktop linux, the last initial QResizeEvent is corrent (there are two, but last is correct)...
QSize(20, 20)
QSize(1920, 1135)When starting the program on Android, the last initial QResizeEvent is only 48, 48, but the widget is full screen / maximized...
// start app on Android (should be portrait dimensions)
D libRotate.so: ../rotate/mylayout.cpp:15 (virtual bool myLayout::eventFilter(QObject*, QEvent*)): QSize(48, 48)
D libRotate.so: ../rotate/mylayout.cpp:15 (virtual bool myLayout::eventFilter(QObject*, QEvent*)): QSize(48, 48)
// rotate to landscape
D libRotate.so: ../rotate/mylayout.cpp:15 (virtual bool myLayout::eventFilter(QObject*, QEvent*)): QSize(1776, 1008)
// rotate to portrait
D libRotate.so: ../rotate/mylayout.cpp:15 (virtual bool myLayout::eventFilter(QObject*, QEvent*)): QSize(1080, 1704)Is this a bug on Android or am I not doing something right?
main.cpp
#include <QApplication> #include <QWidget> #include "mylayout.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget window; myLayout layout; window.setLayout(&layout); window.installEventFilter(&layout); window.setWindowState(Qt::WindowMaximized); window.show(); return a.exec(); }
mylayout.h
#ifndef MYLAYOUT_H #define MYLAYOUT_H #include <QBoxLayout> #include <QEvent> class myLayout : public QBoxLayout { Q_OBJECT public: myLayout(); protected: bool eventFilter(QObject *, QEvent *event); }; #endif // MYLAYOUT_H
mylayout.cpp
#include "mylayout.h" #include <QResizeEvent> #include <QDebug> myLayout::myLayout() : QBoxLayout(QBoxLayout::LeftToRight) { } bool myLayout::eventFilter(QObject *, QEvent *event) { event->ignore(); if (event->type() == QEvent::Resize) { QResizeEvent *resizeEvent = static_cast<QResizeEvent *>(event); qDebug() << resizeEvent->size(); } return false; }
I've tried this in 5.6 and 5.9.4
-
Hi,
You should also add which version of Qt you are using as well as the Android version you are running your code on.
-
@drwho said in QWidget initial resize event size is wrong on Android:
Is this a bug on Android or am I not doing something right?
Neither. You may get multiple (usually speculative) resize events, and this is correct, not a bug. I had observed getting 2-3 such resizes on Linux before the widget is actually shown.