Here is what I use.
ViewerQT is a wrapper around AdapterWidget
ViewerQT.h
Code:
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/GraphicsWindow>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgGA/StateSetManipulator>
#include "AdapterWidget.h"
#include "keyboardHandler.h"
class ViewerQT : public AdapterWidget,public osgViewer::Viewer
{
Q_OBJECT
public:
ViewerQT(QWidget * parent = 0, const char * name = 0,
const QGLWidget * shareWidget = 0, WindowFlags f = 0):
AdapterWidget( parent, name, shareWidget, f )
{
setFocusPolicy(Qt::ClickFocus);
stateManipulator = new
osgGA::StateSetManipulator(getCamera()->getOrCreateStateSet());
addEventHandler(stateManipulator);
keyboardHandler = new keyboardEventHandle();
addEventHandler(keyboardHandler);
trackballManipulator = new osgGA::TrackballManipulator;
setCameraManipulator(trackballManipulator);
addEventHandler(new osgViewer::StatsHandler);
getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
getCamera()->setProjectionMatrixAsPerspective(30.0f,
static_cast<double>(width())/static_cast<double>(height()), 1.0f, 10000.0f);
getCamera()->setGraphicsContext(getGraphicsWindow());
setThreadingModel(osgViewer::Viewer::SingleThreaded);
connect(&_timer, SIGNAL(timeout()), this, SLOT(updateGL()));
_timer.start(10);
}
virtual void paintGL(){frame();}
protected:
osgGA::StateSetManipulator *stateManipulator;
osgGA::TrackballManipulator *trackballManipulator;
keyboardEventHandler* keyboardHandler;
virtual void enterEvent(QEvent *)
{
// entered window
}
virtual void leaveEvent(QEvent *)
{
// left window
}
protected:
QTimer _timer;
signals:
void closing(ViewerQT *win);
};
But since the moc compiler only handles .cpp files you need a ViewerQT.cpp
Code:
#include "AdapterWidget.h"
#include "ViewerQT.h"
I have problems with QOSGWidget, it seems to have a recursive redraw with Qt4.5
(at least on windows)
ViewerQOSG.h
Code:
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/GraphicsWindow>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgGA/StateSetManipulator>
#include "QOSGWidget.h"
#include "keyboardHandler.h"
class ViewerQOSG : public QOSGWidget, public osgViewer::Viewer
{
Q_OBJECT
public:
ViewerQOSG(QWidget * parent = 0, const char * name = 0,
WindowFlags f = 0):QOSGWidget( parent, name, f )
{
setThreadingModel(osgViewer::Viewer::SingleThreaded);
stateManipulator = new
osgGA::StateSetManipulator(getCamera()->getOrCreateStateSet());
addEventHandler(stateManipulator);
trackballManipulator = new osgGA::TrackballManipulator;
setCameraManipulator(trackballManipulator);
addEventHandler(new osgViewer::StatsHandler);
getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
getCamera()->setProjectionMatrixAsPerspective(30.0f,
static_cast<double>(width())/static_cast<double>(height()), 1.0f, 10000.0f);
getCamera()->setGraphicsContext(getGraphicsWindow());
connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
_timer.start(10);}
virtual void paintEvent( QPaintEvent * event ) { frame(); }
protected:
osgGA::StateSetManipulator *stateManipulator;
osgGA::TrackballManipulator *trackballManipulator;
virtual void closeEvent( QCloseEvent * event )
{
_gw->getEventQueue()->closeWindow();
emit closing(this);
}
QTimer _timer;
signals:
void closing(ViewerQOSG *win);
};
And ViewerQOSG.cpp
Code:
#include "QOSGWidget.h"
#include "ViewerQOSG.h"
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=9718#9718
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org