I am trying to implement a mouse press event with QT and OSG but unable to
do it. Pls help.
Below is my ViewerWidget class which is derived from QWidget and
osg::CompositeViewer......In the constructor I got gView which is a
osg::GLWidget, I am trying override mousePressEvent but when I click
message not coming. What I am doing wrong pls help..
My gView pointer is of class CSGraphicsView as below
/////////////////////////////////////////////////////////////////////////////////
#ifndef GVIEW_H
#define GVIEW_H
#include <osg\GraphicsContext>
#include <osgQt\GraphicsWindowQt>
#include <QtGui\qwidget.h>
#include <QtCore\qobject.h>
#include <QtGui\qmouseeventtransition.h>
class CSGraphicsView : public osgQt::GLWidget
{
public:
CSGraphicsView(QWidget* parent=0);
~CSGraphicsView();
virtual void mousePressEvent(QMouseEvent *e);
};
#endif // GVIEW_H
//Implementations is
void CSGraphicsView::mousePressEvent(QMouseEvent *e)
{
QMessageBox msg;
msg.setText("Mouse pressed");
msg.exec();
}//But this msg is not coming when i am pressing mouse.
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
ViewerWidget::ViewerWidget(osgViewer::ViewerBase::ThreadingModel
threadingModel, osg::Group* scene) : QWidget()
{
setThreadingModel(threadingModel);
gView = static_cast<CSGraphicsView*> (addViewWidget(
createCamera(0,0,100,100), scene ));
QGridLayout* grid = new QGridLayout;
grid->addWidget( gView, 0, 0 );
setLayout( grid );
connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
_timer.start( 10 );
}
osgQt::GLWidget* ViewerWidget::addViewWidget( osg::Camera* camera,
osg::Group* scene )
{
osgViewer::View* view = new osgViewer::View;
view->setCamera( camera );
addView( view );
view->setSceneData( scene );
view->addEventHandler( new osgViewer::StatsHandler );
view->setCameraManipulator( new osgGA::TrackballManipulator );
gw = dynamic_cast<osgQt::GraphicsWindowQt*> (
camera->getGraphicsContext() );
return gw ? gw->getGLWidget() : NULL;
}
osg::Camera* ViewerWidget::createCamera( int x, int y, int w, int h, const
std::string& name, bool windowDecoration )
{
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();
}
void ViewerWidget::paintEvent( QPaintEvent* event )
{
frame();
}
/////////////////////////////////////////////////////////////////////////////////
--
Thanks & Regards
Sujan
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org