MouseMoveEvent deal between QGraphicsView and QGraphicsItem
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
Re: MouseMoveEvent deal between QGraphicsView and QGraphicsItem
For changing color of item when mouse is over, you dont need to capture mouse move events.
You simply need a check in the paint function -
Code:
if(option
->state
& QStyle::State_MouseOver)
and then color the item accordingly.
:)
Re: MouseMoveEvent deal between QGraphicsView and QGraphicsItem
Hi,
Ok but what if I want to handle the coloring issue in the mouse move event? I see that this is a general problem and asked by some users of this forum before. Is there a way to reimplement mouse move event both in GraphicsView and GraphicsItem?
Edit: By the way it doesn't work unless I remove option->state part of the if statement. Moreover, although I remove this part, It changes the color that it must change when the program begins, but you know I want to change the color of the item when the mouse is on the item. I could provide my code if you want.
Thanks in advance
Re: MouseMoveEvent deal between QGraphicsView and QGraphicsItem
Hi,
Does anybody has an idea on this subject?
Re: MouseMoveEvent deal between QGraphicsView and QGraphicsItem
You will need to store a variable for color.
Say you have QColor m_color in your graphics item class.
Then in paint event you do the following -
Code:
paint()
{
if(option
->state
& QStyle::State_MouseOver) color = m_color.dark();
painter->fillRect(boundingRect(),color);
}
thats it, and now when you hover over the item, it will become dark.
Remember to set QGraphicsItem::setAcceptHoverEvents to true :)
Re: MouseMoveEvent deal between QGraphicsView and QGraphicsItem
Quote:
Originally Posted by
zgulser
Ok but what if I want to handle the coloring issue in the mouse move event? I see that this is a general problem and asked by some users of this forum before. Is there a way to reimplement mouse move event both in GraphicsView and GraphicsItem?
You must add QGraphicsView::mouseMoveEvent(event) in your reipmlementation code of mouseMoveEvent. Thus your extended QGraphicsView's mouseMoveEvent is able to act like orginal QGraphicsView's mouseMoveEvent.