main widget geometry width ...
-
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:
- constructor is executing before resizeEvent
- 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.25Thanks in advance.
-
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:
- constructor is executing before resizeEvent
- 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.25Thanks in advance.
@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 aresizeEvent()at that point too.See if the above applies in a Qt WASM application?
-
@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 aresizeEvent()at that point too.See if the above applies in a Qt WASM application?