PDA

View Full Version : Mouse Events



Atomic_Sheep
24th April 2013, 12:28
Hi guys, have a nooby question on mouse events.

When you create a window into which you'll put a widget that will then track mouse clicks etc, why are we creating:


void GLWidget::mousePressEvent(QMouseEvent *event)
{
lastPos = event->pos();
}

Inside the Widget and not inside the window that is the container for our widget? I don't know why, but to me it seems more logical that the window is what will track the mouse location and mouse events rather than a widget created inside the window.

Santosh Reddy
24th April 2013, 14:07
There are advantage by allowing the child-widget managing the it own mouse tracking or interactions. If the parent/containter widget tracks the mouse for child, then having new behaviour of mouse in child widgets will change the parent widget also.

Atomic_Sheep
25th April 2013, 09:18
Let me see if I understand what you are saying... depending on implementation, code might be simpler doing it this way? So really, it just depends on what's easier/more appropriate in a given situation?

Santosh Reddy
25th April 2013, 12:44
So really, it just depends on what's easier/more appropriate in a given situation?
Being easier and being appropriate are two different things. I will say it has to be appropriate, even if it not eazy.