Re: GraphicsItem Question
You can override the drag drop mechanism.
ie. starg drag on mouse press / mouse event, move the item whil dragging, and finally on mouse release check the position of item, and adjust accordingly.
Re: GraphicsItem Question
I thought this would only work on widgets....
How would I do this for a graphicsItem?
Re: GraphicsItem Question
Well actually you can do it in Scene.
I had previously done similar thing. I had to move back item if it was dropped in areas not allowed, or align the item to cell if it was dropped somewhere in middle.
I will brief abt my implementation :
1) In scene::mousePressEvent capture the position of mouse press. Check if item lies underneath it.
2) You can start drag on mousepress or mouse move, mouse move is advisable, after the user has picked item and tried to move it.
To start drag, see QDrag. You will need to populate mime data for it.
3) Now in drag move event, move the item that started the drag along with the mouse cursor ( You will need to store item pointer in scene which is under drag..
4) On scene::dropEvent, check the position of item, and do ur calculations.
Hope this helps :)
Re: GraphicsItem Question
Hi
You can do this in the following way,
1. first you should set the ItemIsMovable flag
setFlag(QGraphicsItem::ItemIsMovable,TRUE);
2. then you gotta reimplement itemChange method.
Re: GraphicsItem Question
Hi guys, what about the
QGraphicsItem::MouseRelease
event ???
This is exactly what you need!
Re: GraphicsItem Question
QGraphicsItem::itemChange is also a good option.
But in this case the item will need to know where it can be placed in the scene.
Its more appropriate that a higher level ( scene ) decides what items will be placed where.
Rest , design issue,,, u can choose which suits you.
Re: GraphicsItem Question
Sorry..if this question is too basic
but..I did re implement the QGrahpicsScene
what I have below isn't working
Code:
{
public:
scene()
{
}
{
clear();
}
};
Everytime I drag a graphicsitem from one place to another and release the mouse button..the scene doesn't clear...
Please help
Re: GraphicsItem Question
That's because your method is never called. mouseReleaseEvent() in the scene takes a QGraphicsSceneMouseEvent pointer.