How to enlarge the grap mouse selection
Hi All,
I have a QGraphicsScene in witch I add some items like line etc etc ..
Each item derived from QGraphicsItem and implements the hoverEnterEvent and hoverLeaveEvent to change the color of the entity.
Whit this system I can make an highlight when the mouse pass over the item.
Sometimes to highlight the entity I need to go very close to the entity and in case of thin line it's very difficult to get the entity highlighted and selected.
so there is any way to enlarge the mouse grap ?
I try to use the scene.setSelectionArea function passing a bigger rectangle in this way under the scene.mouseMoveEvent
Code:
path.addRect(scenePos.x()-self.__grapWithd/2, scenePos.y()+self.__grapWithd/2, self.__grapWithd, self.__grapWithd)
self.setSelectionArea(path)
but this code dose not give me any help ..
any help ?
Thanks,
Matteo
Re: How to enlarge the grap mouse selection
Hi,
you might want to overload QGraphicsItem::shape(), which is used by the graphics system to determine if the mouse is actually inside an item:
Code:
{
...
// here is how to enlarge the "grab" area by 5 pixels in either dimension:
path.addRect( boundingRect().adjusted( -5, -5, 5, 5 ) );
return path;
}
};
Tobi
Re: How to enlarge the grap mouse selection
Thanks for you suggestion but I already overwrite the shape method.
And if I do as you suggest the bounding rectangle dose not fit well my shape.
so in case of overlapping bounding box I do not have the correct highlight.
Overloading the shape method is the only way to enlarge the grap mouse ?
Thanks,
Matteo
Re: How to enlarge the grap mouse selection
I was only pointing out the general principle of how this could be done. Of course if you have an arbitrarily shaped item, creating a QPainterPath containing only an enlarged QRectF will be rather crude. As far as I know, the shape() function is the way to go. You might have to be more specific on how you define the PainterPath, to, for example, better fit a single line. Be creative :).
Re: How to enlarge the grap mouse selection
Thanks for your responce ...
I' like to be creative :) and happy too :) ..
I found an easy solution :-)
this is my base class for item:
Code:
...
...
def shape(self):
"""
overloading of the shape method
"""
self.drawShape(path)
painterStrock.setWidth(self.lineWith)
path1=painterStrock.createStroke(path)
return path1
...
..
I derive my object from the above one : and for example the this is the arc one :
Code:
from Interface.Entity.base import *
class Arc(BaseEntity):
"""
this class define the arcQT object
"""
.....
def drawShape(self, painterPath):
"""
overloading of the shape method
"""
painterPath.arcTo(self.boundingRect(),self.startAngle,self.spanAngle)
......
I change the
Code:
painterStrock.setWidth(self.lineWith)
in to
Code:
painterStrock.setWidth(self.lineWith*10)
This enlarge the with of the shape :-)
Regards,
Matteo