PDA

View Full Version : When is the geometry of a QWidget subclass set?



Luc4
3rd May 2011, 10:42
Hi! I'm trying to create a screen driver for Qt Embedded. When a widget is created I should be called a function named createNativeWindow and some other functions like createSurface, with a pointer to the QWidget.

My problem is that I always receive a geometry like (0, 0, 640, 480). I tried to set the size with setGeometry inside my QWidget's constructor and other ways, but I always get that function invoked with that geometry before my call to setGeometry is done.

Question is: why do the QWidget's are always built with that geometry and then moved/resized? Am I doing something wrong?

This is a problem as to implement using accelerated drivers I need to have the geometry set immediately. I cannot reset the geometry afterwards.

Thanks!

high_flyer
3rd May 2011, 16:06
setting the geometry in the constructor will not work, since the widget is not yet visible.
On top of that, there are other considerations such as if the widget is in a layout, or the screen geometry.

What you can do is intercept the showEvent(), and set the geometry there - at that point it should take effect.

Luc4
3rd May 2011, 17:02
Hi! I don't know if I'm understanding correctly, but this is what I tried:


void MyGLWidget::showEvent(QEvent* event)
{
setGeometry(0, 0, 100, 100);
QGLWidget::showEvent(event);
}

Anyway the behavior is the same.
I tried placing logs around the setGeometry call and it seems showEvent is called after my call to the createNativeWindow is placed.
Problem is I need the final geometry in createNativeWindow as my native APIs don't allow resetting the geometry. Any other way?

Thanks!

high_flyer
3rd May 2011, 21:14
First I would try to call setGeometry() after QGLWidget::showEvent() - first call QWidget::showEvent() then setGeometry() and then QGLWidget::showEvent().
If none of this works, you can use what ever initial size you want in createNativeWindow(), and in the showEvent() ask what that size is, and set geomtry accordingly.

Maybe someone with more embedded experience can help you more.