Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QWidget initial resize event size is wrong on Android
QtWS25 Last Chance

QWidget initial resize event size is wrong on Android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 3 Posters 1.4k Views
  • 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.
  • D Offline
    D Offline
    drwho
    wrote on last edited by
    #1

    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

    kshegunovK 1 Reply Last reply
    0
    • D Offline
      D Offline
      drwho
      wrote on last edited by
      #2

      I also tested this code on MacOS and iOS and the initial QResizeEvents on both Qt platforms are correct. This is looking more like a bug in the Qt Android platform.

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

        Hi,

        You should also add which version of Qt you are using as well as the Android version you are running your code on.

        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
        • D drwho

          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

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

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

          Read and abide by the 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