Results 1 to 9 of 9

Thread: showing the name of object +mouse

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: showing the name of object +mouse

    If your sphere is a class deriving from graphics item (and it should be), and it lives in a scene (from what you said, so I assume it's QGraphicsScene) then in the constructor of the sphere set setAcceptHoverEvents( true ), and reimplement hoverEnterEvent and hoverLeaveEvent.

    Something like that:
    Qt Code:
    1. class MySphere : public QGraphicsItem
    2. {
    3. public:
    4. MySphere( QGraphicsItem* parent = 0 ) : QGraphicsItem( parent ), myName( "Not named!" )
    5. {
    6. this->setAcceptHoverEvents( true );
    7. }
    8.  
    9. void setValues( int x, int y, int z )
    10. {
    11. // do something
    12. }
    13.  
    14. void setName( const QString& name )
    15. {
    16. this->myName = name;
    17. }
    18.  
    19. protected:
    20. // add painting and all else you need
    21.  
    22. void hoverEnterEvent( QGraphicsSceneHoverEvent* event )
    23. {
    24. QToolTip::showText( event->screenPos(), this->myName );
    25. }
    26.  
    27. void hoverLeaveEvent( QGraphicsSceneHoverEvent* event )
    28. {
    29. Q_UNUSED( event );
    30.  
    31. QToolTip::hideText();
    32. }
    33.  
    34. private:
    35. QString myName;
    36. };
    To copy to clipboard, switch view to plain text mode 

    Edit:
    btw - dust on my screen is bigger than spheres on this black image

  2. #2
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: showing the name of object +mouse

    If your sphere is a class deriving from graphics item (and it should be), and it lives in a scene (from what you said, so I assume it's QGraphicsScene) then in the constructor of the sphere set setAcceptHoverEvents( true ), and reimplement hoverEnterEvent and hoverLeaveEvent.
    but it's not
    i draw my spheres in the window of qt but i using ogre
    and i store my spheres in vector to draw it i use
    Qt Code:
    1. void OgreWidget::createScene()
    2. {
    3. ogreSceneManager->setAmbientLight(Ogre::ColourValue(1,1,1));
    4.  
    5. for(i=0,i<sphere.size(),i++)
    6. {
    7. int posx=sphere[i].x
    8. int posy=sphere[i].y
    9. int posz=sphere[i].z
    10. ent_sphere = ogreSceneManager->createEntity( sphere[i].name,Ogre::SceneManager:: PT_SPHERE);
    11.  
    12.  
    13. sphereNode= ogreSceneManager->getRootSceneNode()->createChildSceneNode(sphere[i].name, Ogre::Vector3(kk, kkk, kkkk));
    14.  
    15. sphereNode->setScale(0.1f, 0.1f, 0.1f);
    16. sphereNode->attachObject(sphere_marker);
    17. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: showing the name of object +mouse

    Then use Ogre means of finding objects in the scene and retreiving their name.

    Alternative would be to test all elements in the vector on every mouse move, but that is espensive and impractical.

    Besides, if you're using Ogre to display the spheres, why not to use Ogre to display the name as well?
    I'm pretty sure it can be done entirely inside Ogre.

  4. #4
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: showing the name of object +mouse

    thank you
    i just find how i do it in ogre thanks a lot

Similar Threads

  1. Ogre+qt mouse event (add object with mouse problem)
    By rimie23 in forum Qt Programming
    Replies: 7
    Last Post: 24th April 2012, 10:49
  2. mouse tracking showing float numbers
    By fatecasino in forum Qwt
    Replies: 17
    Last Post: 2nd February 2011, 15:40
  3. Child object not showing
    By BalaQT in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2009, 14:46
  4. showing menu mouseclick event with opengl object
    By validator in forum Qt Programming
    Replies: 1
    Last Post: 8th March 2008, 23:25
  5. Replies: 4
    Last Post: 10th May 2006, 22:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.