Hi, I got a file maybe helpful to you. There's a .h file that defines an class
of an osgView. In your project, there should be a ui, and add the code bottom.
#include "Viewer.h"
...
ViewerWidget *osgview;
osgview = new ViewerWidget;
ui.horizontalLayout->addWidget(osgview);
The .h file:
#ifndef _SATLITEVIEWER_H_
#define _SATLITEVIEWER_H_
#include <osg/Node>
#include <QtCore/QTimer>
#include <QtGui/QApplication>
#include <QtGui/QGridLayout>
#include <osgViewer/CompositeViewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgDB/ReadFile>
#include <osgQt/GraphicsWindowQt>
#include <iostream>
class ViewerWidget : public QWidget, public osgViewer::CompositeViewer
{
public:
ViewerWidget(osgViewer::ViewerBase::ThreadingModel
threadingModel=osgViewer::CompositeViewer::SingleThreaded)
{
setThreadingModel(threadingModel);
osg::Group *root = new osg::Group;
osg::Node *satNode = osgDB::readNodeFile("cow.osg");
root->addChild(satNode);
QWidget* widget1 = addViewWidget( createCamera(0,0,100,100),
root );
/*
QWidget* widget2 = addViewWidget( createCamera(0,0,100,100),
osgDB::readNodeFile("glider.osg") );
QWidget* widget3 = addViewWidget( createCamera(0,0,100,100),
osgDB::readNodeFile("axes.osg") );
QWidget* widget4 = addViewWidget( createCamera(0,0,100,100),
osgDB::readNodeFile("fountain.osg") );
QWidget* popupWidget = addViewWidget(
createCamera(900,100,320,240,"Popup window",true),
osgDB::readNodeFile("dumptruck.osg") );
popupWidget->show();
*/
QGridLayout* grid = new QGridLayout;
grid->addWidget( widget1, 0, 0 );
/*grid->addWidget( widget2, 0, 1 );
grid->addWidget( widget3, 1, 0 );
grid->addWidget( widget4, 1, 1 );
setLayout( grid );*/
connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
_timer.start( 10 );
}
QWidget* addViewWidget( osg::Camera* camera, osg::Group* group )
{
StartNetwork();
osgViewer::Viewer* viewer = new osgViewer::Viewer;
viewer->setCamera( camera );
addView( viewer );
viewer->setSceneData( group );
viewer->addEventHandler( new osgViewer::StatsHandler );
viewer->setCameraManipulator( new osgGA::TrackballManipulator );
osgQt::GraphicsWindowQt* gw =
dynamic_cast<osgQt::GraphicsWindowQt*>( camera->getGraphicsContext() );
return gw ? gw->getGraphWidget() : NULL;
}
osg::Camera* createCamera( int x, int y, int w, int h, const
std::string& name="", bool windowDecoration=false )
{
osg::DisplaySettings* ds =
osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
traits->windowName = name;
traits->windowDecoration = windowDecoration;
traits->x = x;
traits->y = y;
traits->width = w;
traits->height = h;
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext( new
osgQt::GraphicsWindowQt(traits.get()) );
camera->setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
camera->setViewport( new osg::Viewport(0, 0, traits->width,
traits->height) );
camera->setProjectionMatrixAsPerspective(
30.0f,
static_cast<double>(traits->width)/static_cast<double>(traits->height), 1.0f,
10000.0f );
return camera.release();
}
virtual void paintEvent( QPaintEvent* event )
{ frame(); }
protected:
QTimer _timer;
};
#endif
At 2014-03-05 17:07:15,"TORRALVO Mickaël" <[email protected]> wrote:
>Hi guys,
>
> I'm currently trying to integrate OSG in a QT environnement. I'm working with
> QT 4.8 32bit and OSG 3.2.1 32 bit. When I create a project and configure it,
> all is ok. My problem is that i don't know how to use the osgQt package. I
> really need help to do this, how to use the package osgQt to add an osgViewer
> into my qt window.
>
>Thank you!
>
>Cheers,
>TORRALVO
>
>Ps : Sorry for my English I'm a french student and my english should be bad.
>
>------------------
>Read this topic online here:
>http://forum.openscenegraph.org/viewtopic.php?p=58436#58436
>
>
>
>
>
>_______________________________________________
>osg-users mailing list
>[email protected]
>http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org