OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

How to ignore keyboard events


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Kilazi
Newbie


Joined: 16 Aug 2012
Posts: 15

PostPosted: Tue Sep 25, 2012 5:17 am    Post subject:
How to ignore keyboard events
Reply with quote

Hello!

I've a problem with Qt once again Smile

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!


Last edited by Kilazi on Thu Sep 27, 2012 4:14 am; edited 1 time in total
Back to top
View user's profile Send private message
Kilazi
Newbie


Joined: 16 Aug 2012
Posts: 15

PostPosted: Wed Sep 26, 2012 9:33 am    Post subject:
Reply with quote

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
Back to top
View user's profile Send private message
Magnus Kessler
Guest





PostPosted: Thu Sep 27, 2012 2:36 pm    Post subject:
Qt crashes on key press
Reply with quote

On Wednesday 26 Sep 2012 11:33:44 Max Sergeev wrote:
Quote:
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


Quote:

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








------------------
Post generated by Mail2Forum
Back to top
Kilazi
Newbie


Joined: 16 Aug 2012
Posts: 15

PostPosted: Fri Sep 28, 2012 4:13 am    Post subject:
Re: Qt crashes on key press
Reply with quote

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.
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 8606

PostPosted: Fri Sep 28, 2012 8:06 am    Post subject:
How to ignore keyboard events
Reply with quote

Hi Max,

On 28 September 2012 05:13, Max Sergeev <> wrote:
Quote:
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.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Kilazi
Newbie


Joined: 16 Aug 2012
Posts: 15

PostPosted: Mon Oct 01, 2012 4:06 am    Post subject:
Re: How to ignore keyboard events
Reply with quote

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!
Back to top
View user's profile Send private message
Kilazi
Newbie


Joined: 16 Aug 2012
Posts: 15

PostPosted: Fri Oct 19, 2012 4:27 am    Post subject:
Reply with quote

So here's some new info, maybe someone will have any ideas about my problem. The problem is, again, when I press any keyboard key, all of my Qt widgets one by one move to certain point of the screen and freeze there, not working anymore. I'm trying to fight it with filtering keyboard events. So,
1) I've tried to add Qt event filter like this:
Code:

class myEventFilter: public QObject
{
  public:
  myEventFilter():QObject()
  {};
  ~myEventFilter(){};

  bool eventFilter(QObject* object,QEvent* event)
  {
      //for all events from keyboard, do nothing
      if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease || event->type() == QEvent::ShortcutOverride)
     {
        std::cout<<"Filtered keyboard event\n";
          return true;
      }
     else
     {
        // for other, do as usual (standard event processing)
        return QObject::eventFilter(object, event);
      }
  }; 
};

Code:

QApplication app(argc1, argv1);
app.installEventFilter(new myEventFilter());

It DOES NOT filter first few clicks, which actually screw up my interface, then starts to work: First I press a key few times, my interface is being completely screwed, and then on like 2nd-4th press it starts to output "Filtered keyboard event".
I thought it would catch the keypresses and not let them fail Qt widgets.

2) I've tried to install osgGA event handler like this:
Code:

class KeyboardEventHandler : public osgGA::GUIEventHandler
    {
      bool isImageCaptured;
    public:
      KeyboardEventHandler(): osgGA::GUIEventHandler()
      {
         isImageCaptured=false;
      }
       virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
       
      bool getImageCapFlag()
      {
         return isImageCaptured;
      }
    };
bool KeyboardEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
     {
        std::cout<<"In Event Handler"<<std::endl;
       switch(ea.getEventType())
       {
       case(osgGA::GUIEventAdapter::KEYDOWN):
          {
          std::cout<<"Event handled "<<std::endl;
          return false;
          }
       default:
          return false;
       }
    }

Code:

viewer.addEventHandler(new KeyboardEventHandler());

this one DOES output "Event handled" at every keypress, though it still has no effect on my problem.

I'm stuck with this problem for very long time, maybe anyone has atleast any guesses what else can I try?

Thanks for your time.

P.S. Robert, my osgViewer certainly has some keyboard event handler, because on the S key, for example, it starts to show some statistics like it osgviewer example.
Back to top
View user's profile Send private message
wh_xiexing
Guest





PostPosted: Fri Oct 19, 2012 5:53 am    Post subject:
about the cull mechanism in osg
Reply with quote

dear friends:

i am newbie . my question is , i have a group which contains a lot a gode. in order to speed the rendering . i don't know whether i need to write a cull callback . or do nothing and let the osg system do the culling work instead . does osg automatically traverse the group and cull the node which lay out the frustum ???


Shawl

------------------
Post generated by Mail2Forum
Back to top
Zhiyu Liu
Guest





PostPosted: Fri Oct 19, 2012 8:03 am    Post subject:
about the cull mechanism in osg
Reply with quote

hi xiexing:
osg offer the frustum culling and  you can set the Culling Mode , also if you want to realize customer culling function please look the osgUtil::CullVisitor

Liu zhiyu

2012/10/19 wh_xiexing < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
Quote:
dear friends:
 
         i am newbie . my question is , i have a group which contains a lot a gode.  in order to speed the rendering .  i don't know whether i need to write a  cull callback .  or do nothing and let the osg system do the culling work instead .  does osg automatically traverse the group and  cull the node which lay out the frustum ???
 
 
Shawl


_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts CompositeViewer / Viewport / problems... aquawicket General 1 Tue Sep 09, 2014 8:51 pm View latest post
No new posts 3d control in scene (ignore scene dep... Jason Anderssen General 4 Fri Aug 15, 2014 1:19 am View latest post
No new posts Key events doesn't work with function... Andrés General 2 Thu Jul 17, 2014 9:22 am View latest post
No new posts [Solved]QMenu stealing events Arnaud C General 1 Mon Jun 02, 2014 4:03 pm View latest post
No new posts iOS and bluetooth keyboard grazer General 0 Thu May 15, 2014 9:17 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP