christina123y (16th March 2009)
You still didn't catch what i mean. I mean that ,only when i remove the mouseMoveEvent(QMouseEvent *event) function in the class which inherit from QGraphicsView , then the rubberbandrect can be achieved.(The rubberband rect function was achieved through the way :reimplement mousePressEvent, mouseMoveEvent , mouseReleaseEvent function in the class which inherit from QGraphicsItem).
If i don't remove the mousemoveEvent function in the class which inherit from QGraphicsView, then the rubberbandrect can't be achieved. Now i think the main reason is that the class which inherit from QGraphicsView has intercepted the mouse event before the class which inherit from the item.
christina123y (17th March 2009)
Please note the following:
A MouseEvent propagates at first to the item under the mouse.
If you subclass the item and call QGraphicsItem::mouseXXXEvent(envent), it will be propagated further. If you don't do that, the event is seen as processed and "dies".
But if you call the parent handler, then you will meet this event also in the scene and the view again.
Regards,
Olli
christina123y (17th March 2009)
Did you have a look at the example in Qt Demo ?
You can refer it from here also .
You can select items through rubberbanding. Look into the code how they did it.
christina123y (17th March 2009)
Oh, thank you very much!
I think this will help me! because i didn't call QGraphicsItem::mouseXXXEvent(envent), so maybe the event is seen as processed and "dies",but i tried this ,but the rubberband rect hadn't been drawn and nothing do to the graph, except the mouse postion tracking .
i will try again!
And now i have remove all mousePressEvent,mouseMoveEvent,mouseReleaseEvent in the class which inherit from the QGraphicsItem.
Then i write the code of zoom in through select a rubberband rect in the class which inherit from the QGraphicsView.At last ,the mouse postion tracking didn't colides with the selection of rubberband rect. and this resolve my problem.
As aamer4yu's reply of #6, he said that
"I dont think you have to go to items level for that. What you need to do is - catch mouse events in your scene / view. Draw the rubberband in mouse move events, and finally on mouse release event you capture a rect, from the mousepress(x,y) and mouserelease(x,y).
Now you convert this rect in to scene rect, and call QGraphicsView::fitInView()
Thats it, you are zoomed in :-) , and you only had to capture events in the view "
He was right, i needn't have to go to the items level. both mouse position tracking and rubberband rect zoom can both be handed in the QGraphicsView level.
but i still puzzled why the view class intercepted the mouse event before the item ?
christina123y (18th March 2009)
Now i counter another problem, the class which inherit from QGraphicsItem can't be moved and seletable.
and i have setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable)
in it's constructor,but it still can move.(i also try to put setFlags of this item in any possible postion, but it still can't be moved)
but i also add a ellipse item in the scene, howerver,the ellipse item can move.
Why? I don't understand why this happen to this item?
Wish anyone's help soonly !Thank you!
Are you overriding some events of the item you inherited from graphicsitem ?
If yes, are you calling the base class QGraphicsItem methods from there ?
Hi,
I have very similar problem regarding this subject.
I have a QGraphicsView and QGraphicsScene and some QGraphicsItem (as usual). For again to zoom upan a rubberband action I needed to reimplement mouse move event in QGraphicsView. Moreover, I also want to change the color of the item whenever mouse moves on the item. So it seemed I need to reimplement the mouse move event also in the QGraphicsItem. But I doesn't work. I also tried out eventFilter thing.
Can anyone help me?
Thanks in advance.
Bookmarks