简体   繁体   中英

Qt and OSG Integration Issue, Scene Graph Disappearing

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 :

...
class AbstractQTGLWidget ... {
  ...
protected:
  QSize sizeHint() const { return QSize(400,300); }
  ...
};

I think (but not 100% sure) that the problem is within the constructor, when the width() and height() 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: 0

With 1: 用1

I've tried reproducing the problem with the code you provided. However, I wasn't able to get the latest OpenSceneGraph (and its OpenThreads dependency) building.

So I made your example even simpler, and used a QFrame instead of the OSG widget.

Having experimented with the code quite a lot, my suggestion is to try adding a call:

 viewer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM