qt - Items in a QGraphicsScene near the mouse -


i trying find items under mouse in scene. code using follows:

    qpainterpath mousepath;     mousepath.addellipse(mouseevent -> pos(),5,5);     qlist<qgraphicsitem *> itemscandidate = this->items(mousepath);     if (!(itemscandidate.contains(lastselecteditem))) lastselecteditem =itemscandidate.first(); 

ps: refers scene.

the code should find items intersected small circle around mouse position , keep item pointer unchanged if previous intersected 1 still intersected, or take first in qlist otherwise.

unfortunately, code not work items inside each other. example, if have rect side rect, outer rect intersecting mouse position when 1 near inner rect. how can solve this?

update: seems not problem polygons, rect, ellipses, etc.

update: code in redefined scene::mousemoveevent

you can reimplement ‍mousemoveevent in ‍qgraphicsview‍ capture mouse move events in view , track items near mouse like:

void myview::mousemoveevent(qmouseevent *event) {     qpointf mousepoint = maptoscene(event->pos());      qreal x = mousepoint.x();     qreal y = mousepoint.y();      foreach(qgraphicsitem * t , items())     {         int dist = qsqrt(qpow(t->pos().x()-x,2)+qpow(t->pos().y()-y,2));         if( dist<70 )         {             //do whatever         }     }      qgraphicsview::mousemoveevent(event); } 

Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -