[osg-users] Qt crashes on key press

78 views
Skip to first unread message

Max Sergeev

unread,
Sep 25, 2012, 1:17:55 AM9/25/12
to osg-...@lists.openscenegraph.org
Hello!

I've a problem with Qt once again :)

There is OSG scene, where I put some Qt controls, like in osgQtBrowser example, where Qt controls are getting rendered like OSG objects (I create camera for them and stuff).
So, when I press any key on keyboard, Qt controls just jump somewhere around the screen and stop reacting on any actions (mouse clicks etc).
What can this possibly be? Or, in other case, is there a way to make Qt objects (each in it's own camera) ignore any keyboard actions?

Sorry for poor explanation, and thank you in advance!

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





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Max Sergeev

unread,
Sep 26, 2012, 5:33:44 AM9/26/12
to osg-...@lists.openscenegraph.org
Allright, I think I've got another, more global question: is there a way to make OSG ignore all keypresses, all keyboard events? Just like this, so it would not react on S, W or even Escape keypresses

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

Magnus Kessler

unread,
Sep 27, 2012, 10:36:27 AM9/27/12
to osg-...@lists.openscenegraph.org
On Wednesday 26 Sep 2012 11:33:44 Max Sergeev wrote:
> Allright, I think I've got another, more global question: is there a way to
> make OSG ignore all keypresses, all keyboard events? Just like this, so it
> would not react on S, W or even Escape keypresses

You can stop a Viewer from exiting on Escape by calling

viewer.setKeyEventSetsDone(0);

on it.

The osgvnc example is using this, for instance. See the ViewerBase
documentation for more information about this.

HTH,

Magnus

Max Sergeev

unread,
Sep 28, 2012, 12:13:54 AM9/28/12
to osg-...@lists.openscenegraph.org

Magnus Kessler wrote:
> On Wednesday 26 Sep 2012 11:33:44 Max Sergeev wrote:
> You can stop a Viewer from exiting on Escape by calling
>
> viewer.setKeyEventSetsDone(0);
>
> on it.
>
> The osgvnc example is using this, for instance. See the ViewerBase
> documentation for more information about this.
>


Thanks for the answer, it does block the Escape key I suppose, but still didnt solve my problem: qt controls on click of Escape key still change their positions and become unclickable. I thought there could be some more global way, like blocking the key events for whole application -- like they just are not clicked.
Will do check the example and documentation you suggested, thanks.

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

Robert Osfield

unread,
Sep 28, 2012, 4:07:57 AM9/28/12
to osg-...@lists.openscenegraph.org
Hi Max,

On 28 September 2012 05:13, Max Sergeev <sergee...@gmail.com> wrote:
> Thanks for the answer, it does block the Escape key I suppose, but still didnt solve my problem: qt controls on click of Escape key still change their positions and become unclickable. I thought there could be some more global way, like blocking the key events for whole application -- like they just are not clicked.
> Will do check the example and documentation you suggested, thanks.

The osgViewer classes are built around not having any event handlers
by default and it's the application developers responsibility to add
these to their applications, so it's not a case of working out how to
block events but rather just adding the event handlers you need. The
only exceptions to this rule is the escape key handling setting done -
which is on by default but can be switched off, and the
TrackballManipulator that is added as fallback if no other camera
manipulator is attached when you call Viewer::run().

Robert.

Max Sergeev

unread,
Oct 1, 2012, 12:06:44 AM10/1/12
to osg-...@lists.openscenegraph.org

robertosfield wrote:
>
> The osgViewer classes are built around not having any event handlers
> by default and it's the application developers responsibility to add
> these to their applications, so it's not a case of working out how to
> block events but rather just adding the event handlers you need. The
> only exceptions to this rule is the escape key handling setting done -
> which is on by default but can be switched off, and the
> TrackballManipulator that is added as fallback if no other camera
> manipulator is attached when you call Viewer::run().
>
> Robert.
>


I thought so too, but even as I did not add any key event handlers, my Qt elements jump around the screen as I press anything! Could it be something about Qt? The thing is Qt is all fine while it's in screen mode, I mean, when I use Qt forms etc -- but when I put it inside OSG scene as 3d-model, things start to happen.

Here is code, how I create button and put it on scene:

Code:

QWidget* widget = 0;
widget = new QWidget;
widget->setLayout(new QVBoxLayout);
QPushButton* button = new MyButton(buttonText);
button->setFixedSize(width-30,height-10);
widget->layout()->addWidget(button);
// widget->setGeometry(0, 0, 800,600);
QGraphicsScene* graphicsScene = 0;
osg::ref_ptr<osgQt::QWidgetImage> widgetImage = new osgQt::QWidgetImage(widget);
#if (QT_VERSION >= QT_VERSION_CHECK(4, 5, 0))
widgetImage->getQWidget()->setAttribute(Qt::WA_TranslucentBackground);
#endif
widgetImage->getQGraphicsViewAdapter()->setBackgroundColor(QColor(0, 0, 0, 0));
graphicsScene = widgetImage->getQGraphicsViewAdapter()->getQGraphicsScene();
osg::Camera* camera = 0;
osg::Geometry* quad = osg::createTexturedQuadGeometry(osg::Vec3(0,0,0), osg::Vec3(1,0,0), osg::Vec3(0,1,0), 1, 1);


osg::StateSet* stateset = quad->getOrCreateStateSet();
stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
osg::Geode* geode = new osg::Geode;
geode->addDrawable(quad);

osg::MatrixTransform* mt = new osg::MatrixTransform;

osg::Texture2D* texture = new osg::Texture2D(widgetImage.get());
texture->setResizeNonPowerOfTwoHint(false);
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
mt->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);

osgViewer::InteractiveImageHandler* handler;

camera = new osg::Camera;
camera->setProjectionResizePolicy(osg::Camera::FIXED);
camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1,0,1));
//camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024);
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(osg::Matrix::identity());
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
camera->setRenderOrder(osg::Camera::POST_RENDER);
camera->addChild(geode);
camera->setViewport(x,y,width,height);


mt->addChild(camera);

handler = new osgViewer::InteractiveImageHandler(widgetImage.get(), texture, camera);

mt->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
mt->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
mt->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
mt->getOrCreateStateSet()->setAttribute(new osg::Program);

osg::Group* overlay = new osg::Group;
overlay->addChild(mt);
quad->setEventCallback(handler);
quad->setCullCallback(handler);
scene->addChild(overlay);




Anyway, the thing I was looking for is some blocker for any keyboard press, maybe even not through OSG but in whole C++ windows application? Like, you know, a firewall for key events so I could "open ports" only for those I need?

Thanks for your time![/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50354#50354
Reply all
Reply to author
Forward
0 new messages