Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. main widget geometry width ...
Forum Updated to NodeBB v4.3 + New Features

main widget geometry width ...

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
3 Posts 2 Posters 451 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.
  • 1 Offline
    1 Offline
    1XU7
    wrote on last edited by
    #1

    hello!
    there is somethng really strange while reading this->geometry().width(),

    from constructor, it returns 640 (i think this is the default width main widget value..)

    MyWidget::MyWidget(){
         qDebug() << this->geometry().width();      // returns 640 even with full screen browser
    }
    

    from void resizeEvent(QResizeEvent*) it returns real browser width.

    void MyWidget::resizeEvent(QResizeEvent* _e){
         qDebug() << this->geometry().width();      // returns 1930, real browser width.
    }
    

    as you can see, i need to adjust in constructor some parameters:

    MyWidget::MyWidget(){
         //create a button as long as browser width...
         myButton->setGeometry(0, 0, this->geometry().width(), 30);
    }
    

    but that will create a button with geometry 0, 0, 640, 30.

    well, i thought i could do this to fix it, since i noticed resizeEvent is executing very early but not enought sure earliest than constructor..

    //MyWidget.h
    private: 
         int PageWidth {0};
    
    //MyWidget.cpp
    MyWidget::MyWidget(){
         myButton->setGeometry(0, 0, PageWidth, 30);
    }
    
    void MyWidget::resizeEvent(QResizeEvent* _e){
         PageWidth = this->geometry().width();
    }
    

    but myButton geometry was 0, 0, 0, 30 ...

    possible scenarios for this:

    1. constructor is executing before resizeEvent
    2. resizeEvent is executing before constructor but is not assigning PageWidth var. (this is less probable).

    i don´t get what else can try.. this only happens on Qt webassembly.

    My specs:
    Qt 6.5.2
    Emscripten 3.1.25

    Thanks in advance.

    JonBJ 1 Reply Last reply
    0
    • 1 1XU7

      hello!
      there is somethng really strange while reading this->geometry().width(),

      from constructor, it returns 640 (i think this is the default width main widget value..)

      MyWidget::MyWidget(){
           qDebug() << this->geometry().width();      // returns 640 even with full screen browser
      }
      

      from void resizeEvent(QResizeEvent*) it returns real browser width.

      void MyWidget::resizeEvent(QResizeEvent* _e){
           qDebug() << this->geometry().width();      // returns 1930, real browser width.
      }
      

      as you can see, i need to adjust in constructor some parameters:

      MyWidget::MyWidget(){
           //create a button as long as browser width...
           myButton->setGeometry(0, 0, this->geometry().width(), 30);
      }
      

      but that will create a button with geometry 0, 0, 640, 30.

      well, i thought i could do this to fix it, since i noticed resizeEvent is executing very early but not enought sure earliest than constructor..

      //MyWidget.h
      private: 
           int PageWidth {0};
      
      //MyWidget.cpp
      MyWidget::MyWidget(){
           myButton->setGeometry(0, 0, PageWidth, 30);
      }
      
      void MyWidget::resizeEvent(QResizeEvent* _e){
           PageWidth = this->geometry().width();
      }
      

      but myButton geometry was 0, 0, 0, 30 ...

      possible scenarios for this:

      1. constructor is executing before resizeEvent
      2. resizeEvent is executing before constructor but is not assigning PageWidth var. (this is less probable).

      i don´t get what else can try.. this only happens on Qt webassembly.

      My specs:
      Qt 6.5.2
      Emscripten 3.1.25

      Thanks in advance.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @1XU7 said in main widget geometry width ...:

      this only happens on Qt webassembly.

      I have not used WASM. But for a Qt widgets application at least basically you cannot call/rely on the return value for "visual" things like size until the widget has been shown. So it's OK in, say, resizeEvent() but not in a constructor since the widget has not been shown yet at that time and so has no proper visual dimensions calculated.

      If you subclass a widget you get a showEvent() when it is first shown, which is when the dimensions are first made valid. I don't know whether you also get a resizeEvent() at that point too.

      See if the above applies in a Qt WASM application?

      1 1 Reply Last reply
      2
      • JonBJ JonB

        @1XU7 said in main widget geometry width ...:

        this only happens on Qt webassembly.

        I have not used WASM. But for a Qt widgets application at least basically you cannot call/rely on the return value for "visual" things like size until the widget has been shown. So it's OK in, say, resizeEvent() but not in a constructor since the widget has not been shown yet at that time and so has no proper visual dimensions calculated.

        If you subclass a widget you get a showEvent() when it is first shown, which is when the dimensions are first made valid. I don't know whether you also get a resizeEvent() at that point too.

        See if the above applies in a Qt WASM application?

        1 Offline
        1 Offline
        1XU7
        wrote on last edited by
        #3

        @JonB i Will give a try to showEvent and comment

        Thanks!

        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