|
楼主 |
发表于 2013-1-29 14:34:16
|
显示全部楼层
liuzhiyu123 发表于 2013-1-29 14:00
不清楚您在说什么,这个跟qt又有什么必然的联系?
我这个在一般OSG程序里就可以 但是结合QT之后就不行了啊
这个是adapterwidget OSGWidget继承的这个类
#include "adapterwidget.h"
AdapterWidget::AdapterWidget(QWidget *parent)
: QGLWidget(parent)
{
_gw = new osgViewer::GraphicsWindowEmbedded(0,0,width(),height());
setFocusPolicy(Qt::ClickFocus);
}
AdapterWidget::~AdapterWidget()
{
}
QSize AdapterWidget::minimumSizeHint() const
{
return QSize(50, 50);
}
QSize AdapterWidget::sizeHint() const
{
return QSize(400, 400);
}
void AdapterWidget::resizeGL(int width, int height)
{
_gw->getEventQueue()->windowResize(0, 0, width, height );
_gw->resized(0,0,width,height);
}
void AdapterWidget::keyPressEvent( QKeyEvent* event )
{
_gw->getEventQueue()->keyPress( (osgGA::GUIEventAdapter::KeySymbol) *(event->text().toAscii().data() ) );
}
void AdapterWidget::keyReleaseEvent( QKeyEvent* event )
{
_gw->getEventQueue()->keyRelease( (osgGA::GUIEventAdapter::KeySymbol) *(event->text().toAscii().data() ) );
}
void AdapterWidget::mouseMoveEvent( QMouseEvent* event )
{
_gw->getEventQueue()->mouseMotion(event->x(), event->y());
}
void AdapterWidget::mousePressEvent( QMouseEvent* event )
{
int button = 0;
switch(event->button())
{
case(Qt:eftButton): button = 1; break;
case(Qt::MidButton): button = 2; break;
case(Qt::RightButton): button = 3; break;
case(Qt::NoButton): button = 0; break;
default: button = 0; break;
}
_gw->getEventQueue()->mouseButtonPress(event->x(), event->y(), button);
}
void AdapterWidget::mouseReleaseEvent( QMouseEvent* event )
{
int button = 0;
switch(event->button())
{
case(Qt::LeftButton): button = 1; break;
case(Qt::MidButton): button = 2; break;
case(Qt::RightButton): button = 3; break;
case(Qt::NoButton): button = 0; break;
default: button = 0; break;
}
_gw->getEventQueue()->mouseButtonRelease(event->x(), event->y(), button);
}
void AdapterWidget::wheelEvent( QWheelEvent* event )
{
if( event->delta()<0 )
_gw->getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_DOWN);
else if( event->delta()>0 )
_gw->getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_UP);
//osgGA::GUIEventAdapter::ScrollingMotion::SCROLL_LEFT
}
|
|