So I’ve run into a problem while integrating QT and OSG. I’ve had a QT/OSG program that been working just fine. The layout is simlar to what you see below.
|--------------------------|
| 1 | 2 |
| | |
| | |
| | |
| | |
| | |
| |-------------------|
| | 3 |
| | |
|--------------------------|
The central widget consists of a QFrame which has three sub widgets and is using grid layout. Widget 1 is a QFrame also with a grid layout. Widget 2 is the OSG viewer as described below. Widget 3 is a QFrame also with a grid layout.
Two is populated with a widget modeled after the example in osgviewerQT.cpp. Basically it uses an embedded window and I have a QTimer that fires every 10 milliseconds and calls the osg frame function.
I have 4 other widgets. Two QLabels and two QTables which I populate dynamically. I’ve been adding all four of these widgets to 1’s grid layout. When I do that everything works nicely and I get my nice scene graph in 2. If I make one change, moving these four widgets from 1 to 2’s grid layout suddenly my scene graph disappears. Any ideas what is going wrong? I’ve checked in valgrind so I am pretty sure its not a memory issue and rather its how I am using the lib. I’ve confirmed the frame function is being called.
I’ve found a solution: you must add a size hint for the viewer control. Something like this will be ok:
In
AbstractQTGLWidget.hpp:I think (but not 100% sure) that the problem is within the constructor, when the
width()andheight()properties are used.Different layouts, different priorities in establishing the width and height of each widget, and so the constructor is blind to the final width and height.
Giving an initial width and height, I assume the underlying osg viewer can calculate the camera and object references, and begin the process accordingly. Later changes in width and height are applied correctly, as the object was initiated with correct sizes, though not final.
Maybe the control thinks it has a size of 0 by 0 pixels, and the renderer gets crazy initializing…
With 0:

With 1:
