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:
{
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:
};
class MySphere : public QGraphicsItem
{
public:
MySphere( QGraphicsItem* parent = 0 ) : QGraphicsItem( parent ), myName( "Not named!" )
{
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
void hoverEnterEvent( QGraphicsSceneHoverEvent* event )
{
QToolTip::showText( event->screenPos(), this->myName );
}
void hoverLeaveEvent( QGraphicsSceneHoverEvent* event )
{
Q_UNUSED( event );
QToolTip::hideText();
}
private:
QString myName;
};
To copy to clipboard, switch view to plain text mode
Edit:
btw - dust on my screen is bigger than spheres on this black image
Bookmarks