PDA

View Full Version : Sending event from child widget



scascio
28th September 2009, 11:44
Dear Qt workers,

Working with QGraphicsView, I managed an overlayed child QWidget attached to the mouse.
Since I need to control my view from the mouse, I catch events in the widget then I can call slots by emitting signals.

But my problem is to transmit mouse events to QGraphicsItem, for instance to take benefit of default selecting and moving, or change item state by double clicking.
Mouse event cannot reach items, event if I write :


void QCursorView::mouseDoubleClickEvent(QMouseEvent * event) {
QWidget::mouseDoubleClickEvent(event);
QMouseEvent translatedEvent(event->type(),
mapTo(parentWidget(), event->pos()),
event->button(),
event->buttons(),
event->modifiers());
qApp->sendEvent(parentWidget(), &translatedEvent);
}

Neither the view receive the event.

What is the way to send events properly?
Is there any restriction according to widget hierarchy and event calling stack?

Thanks by advance

PS: I cannot use Qt::WA_TransparentForMouseEvents since I need to do some computation in the child widget in response of some events.
since

S.Cascio

kwisp
28th September 2009, 12:09
why you are writing this order:

QWidget::mouseDoubleClickEvent(event);
QMouseEvent translatedEvent(event->type(),
mapTo(parentWidget(), event->pos()),
event->button(),
event->buttons(),
event->modifiers());
qApp->sendEvent(parentWidget(), &translatedEvent);


why not



QMouseEvent translatedEvent(event->type(),
mapTo(parentWidget(), event->pos()),
event->button(),
event->buttons(),
event->modifiers());
qApp->sendEvent(parentWidget(), &translatedEvent);
QWidget::mouseDoubleClickEvent(event);

why you are calling
QWidget::mouseDoubleClickEvent(event);
at all?

scascio
28th September 2009, 12:39
Thanks for your time.

The code provided is in the child widget and I need to transmit the event to the parent widget with mouse coordinates transformed.
So, calling base class and sendEvent are not working on same object. So instructions are independant, aren't they?

Calling the base class is just a reflex.

kwisp
28th September 2009, 12:49
Thanks for your time.
So instructions are independant, aren't they?

I think no. It is in dependences.
try to comment this line.


QWidget::mouseDoubleClickEvent(event);

scascio
28th September 2009, 13:07
It does not work.
Commented or not, before or after. Same result : event is not transmitted to parent view, so neither to item.

I tried to ignore event without success.

The only way I can make it work is to emit signals and catch them into slots.
But then I must rewrite basic features of QGraphicsView, such as clicking an item to select it, anywhere to unselect, moving items, ... How sad I am

kwisp
28th September 2009, 13:25
hm...
may be you must use
QGraphicsSceneMouseEvent ,
QGraphicsItem::parentItem()

scascio
28th September 2009, 21:18
I dont understand what you mean

I can't create any QGraphicsSceneMouseEvent since its constructor is private.
And I read in the doc that the QMouseEvent in the QGraphicsView is translated to a QGraphicsSceneMouseEvent then sent to the QGraphicsScene and then to the QGraphicsItem.

So, theorically, I only need to send event to the view.