showing the name of object +mouse
Hi
i am beginer in Qt programming
i want to whe i put my mose on an object in the screen it show me his name
for example : i have two shepe in my scene an each object has name
object1.name
object2.name
or has index(num)
object1.index
object2.index
i want when i put my mouse on the object1 i see his name (in label or in onother thing) , is it possible to do tat in qt ? and how i do that ?
Re: showing the name of object +mouse
Hi,
Lets say that your application is based on qwidget. So you can re-implement moveEvent:
Code:
void myQWidgetClass
::moveEvent ( QMoveEvent * event
) {
child = childAt (event->pos.x(), event->pos.y());
if (child)
{
qDebug() << child.objectName();
}
}
Carlos.
Re: showing the name of object +mouse
hi ,
i t dos not work
it make to me error in this line
Code:
child = childAt (e->pos.x(), e->pos.y());
Quote:
left of '->pos' must point to class/struct/union/generic type
there is another thing
Code:
qDebug() << child.objectName();
how it now the name of object (there are many object and my object name are like this object[i].name ?
for exemple
object[1].name="A1"
object[2].name="C"
.
.
.
.
i can use index too
object[1].num=2
object[2].num=5
.
.
Re: showing the name of object +mouse
This is the code:
Code:
{
child = this->childAt(e->pos().x(),e->pos().y());
if (child)
{
qDebug() << child->objectName();
}
}
You need to activate setMouseTracking(true) to all objects for it to work.
Quote:
how it now the name of object (there are many object and my object name are like this object[i].name ?
for exemple
object[1].name="A1"
object[2].name="C"
.
.
.
.
i can use index too
object[1].num=2
object[2].num=5
.
.
Its is not clear on what you want to do.
1 Attachment(s)
Re: showing the name of object +mouse
hi ,
yhats what i see
Attachment 7635
i have many spheres
i draw this spheres like that
Code:
for(i=0,i<sphere.size(),i++)
{
int posx=sphere[i].x
int posy=sphere[i].y
int posz=sphere[i].z
..................
}
and for each sphre[i] there is name
Code:
char name=sphere[i].name
i want when i put (don't clic) on sphere i can see her name
(each red sphere has name deferent to the others)
you understand me now?
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:
Code:
{
public:
{
this->setAcceptHoverEvents( true );
}
void setValues( int x, int y, int z )
{
// do something
}
void setName( const QString& name )
{
this->myName = name;
}
protected:
// add painting and all else you need
{
QToolTip::showText( event
->screenPos
(), this
->myName
);
}
{
Q_UNUSED( event );
}
private:
};
Edit:
btw - dust on my screen is bigger than spheres on this black image :)
Re: showing the name of object +mouse
Quote:
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
Code:
void OgreWidget::createScene()
{
ogreSceneManager->setAmbientLight(Ogre::ColourValue(1,1,1));
for(i=0,i<sphere.size(),i++)
{
int posx=sphere[i].x
int posy=sphere[i].y
int posz=sphere[i].z
ent_sphere = ogreSceneManager->createEntity( sphere[i].name,Ogre::SceneManager:: PT_SPHERE);
sphereNode= ogreSceneManager->getRootSceneNode()->createChildSceneNode(sphere[i].name, Ogre::Vector3(kk, kkk, kkkk));
sphereNode->setScale(0.1f, 0.1f, 0.1f);
sphereNode->attachObject(sphere_marker);
}
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.
Re: showing the name of object +mouse
thank you
i just find how i do it in ogre thanks a lot