Results 1 to 4 of 4

Thread: When is the geometry of a QWidget subclass set?

  1. #1
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default When is the geometry of a QWidget subclass set?

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: When is the geometry of a QWidget subclass set?

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: When is the geometry of a QWidget subclass set?

    Hi! I don't know if I'm understanding correctly, but this is what I tried:

    Qt Code:
    1. void MyGLWidget::showEvent(QEvent* event)
    2. {
    3. setGeometry(0, 0, 100, 100);
    4. QGLWidget::showEvent(event);
    5. }
    To copy to clipboard, switch view to plain text mode 

    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!

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: When is the geometry of a QWidget subclass set?

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 1
    Last Post: 3rd February 2011, 10:38
  2. Replies: 4
    Last Post: 17th January 2011, 13:05
  3. Replies: 2
    Last Post: 27th May 2010, 01:55
  4. Replies: 8
    Last Post: 12th February 2010, 02:41
  5. Replies: 2
    Last Post: 1st January 2008, 13:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.