PDA

View Full Version : QMouseEvent vs QHoverEvent



sajis997
3rd August 2011, 16:27
Hello forum,

I am playing around with the elastic node example and have the some issue to discuss with:


When the scene loads the nodes are already connected with edges and i want to change this attribute. The edge will be connected with two adjacent nodes in the following manner:

1. When the user move the cursor over one of the adjacent nodes and press the Ctrl modifier and the nodes gets highlighted and remains highlighted as long as the Ctrl button is pressed while the cursor is on the node.


2. When the user move the mouse cursor while pressing the Ctrl button , the edge arrow will be drawn from the source node. And When the user cursor reach the destination node while Ctrl modifier pressed , the edge arrow will finish drawing at the destination node.


Initially , I did the following changes inside the node class :


1. Inside the constructor , i have set the



setAcceptHoverEvents(true);



declare the following functions



void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
if(event->modifiers() == Qt::ControlModifier)
{
update();
QGraphicsItem::hoverMoveEvent(event);
}
}



But i am getting the hightlight effect with the existing mouseReleaseEvent(). I should be getting the highlight effect only after mouse hover move event with the Ctrl modifier.


Any further will be very helpful.

Thanks
Sajjad