Hi,

I am trying to integrate an osg viewer into a Qt user interface. To do this I 
am using the osg viewer widget from the OpenSceneGraph 3.0 Cookbook. If I set 
the widget to fullscreen with the Qt method showFullScreen(). If I do this I 
have a gray border around my viewport. To eliminate the border I try to set the 
margin of the layout which includes the osgviewer to 0. But if I do this the Qt 
widget with viewer is not shown anymore. If I set the margin value to 1 then it 
works but I have again a small gray border. 

I know that this is working with OpenSG. Is there maybe a problem with osg?? 
Does someone has a solution for this problem??

Here is my code (Sorry I don'T know why the tabs are shown like this):

viewerwidget.h

Code:

#ifndef VIEWERWIDGET_H
#define VIEWERWIDGET_H

// C++ includes
#include <iostream>

// Qt includes
#include <QtCore/QtCore>
#include <QtGui/QtGui>

// OSG includes
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/Viewer>
#include <osgQt/GraphicsWindowQt>

class ViewerWidget : public QWidget
{
public:
        ViewerWidget( QWidget *parent = 0, Qt::WFlags flags = 0 ) 
          : QWidget(parent, flags)
        {
                osg::Camera* camera = createCamera( 0, 0, 640, 480 );
                osg::Node* scene = osgDB::readNodeFile("cow.osg");
                m_viewer.setCamera( camera );
                m_viewer.setSceneData( scene );
                m_viewer.addEventHandler( new osgViewer::StatsHandler );
                m_viewer.setCameraManipulator( new osgGA::TrackballManipulator 
);

                // Use single thread here to avoid known issues under Linux
                m_viewer.setThreadingModel( osgViewer::Viewer::SingleThreaded );

                osgQt::GraphicsWindowQt* gw = 
dynamic_cast<osgQt::GraphicsWindowQt*>( camera->getGraphicsContext() );
                if ( gw )
                {
                        QVBoxLayout* layout = new QVBoxLayout;

                        ///////////////////////////////////////
                        layout->setMargin(0);
                        ///////////////////////////////////////

                        layout->addWidget( gw->getGLWidget() );
                        setLayout( layout );
                }

                connect( &m_timer, SIGNAL(timeout()), this, SLOT(update()) );
                m_timer.start( 40 );
        }

        ~ViewerWidget() {}

        osg::Camera* createCamera( int x, int y, int w, int h )
        {
                osg::DisplaySettings* ds = 
osg::DisplaySettings::instance().get();

                osg::ref_ptr<osg::GraphicsContext::Traits> traits = new 
osg::GraphicsContext::Traits;
                traits->windowDecoration = false;
                traits->x = x;
                traits->y = y;
                traits->width = w;
                traits->height = h;
                traits->doubleBuffer = true;

                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();
        }

protected:
        virtual void paintEvent( QPaintEvent* event )   { m_viewer.frame(); }
        osgViewer::Viewer       m_viewer;
        QTimer                          m_timer;
};

#endif  // VIEWERWIDGET_H




main.cpp

Code:

#include <QtGui/QApplication>

#include "viewerwidget.h"

int main(int argc, char *argv[])
{
   QApplication app( argc, argv );

   ViewerWidget* widget = new ViewerWidget(0,Qt::WindowStaysOnTopHint | 
Qt::SplashScreen);
   widget->setGeometry( 0, 0, 800, 600 );
   widget->showFullScreen();
   widget->show();

return app.exec();
}





Thank you!

Cheers,
Markus

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=47603#47603





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to