PDA

View Full Version : getWidgetAt/getChildAt(global position) for elements under QGraphicsProxyWidget



lgvier
24th April 2009, 09:08
Hello folks,

I'm looking for a way to retrieve what widget is under position x,y including the ones inside QGraphicsProxyWidgets.
QApplication and QWidget's methods return the scene widget instead of the widget inside it.

If that's not possible.. if there's a way to post a mouse event "globally" that will reach the children widget at certain position, that would do the trick. I'm using postEvent, but I have to pass the target widget, so I have to find that widget first.

Thanks a lot for any help :)

lgvier
25th April 2009, 23:06
Hello,

I'll answer myself in case somebody needs the same thing in the future..

You map the global coordinates to the view:


QPoint relativePos = view->mapFromGlobal(pos);


Then the view local coordinates to the scene:


QPointF scenePos = graphicsView->mapToScene(relativePos);


And finally the scene pos to the GraphicsItem pos


QPointF sceneRelPos = item->mapFromScene(scenePos);


Now proxy->widget()->childAt(sceneRelPos.toPoint) will return the widget that was hit inside the proxy.

Cheers
Geovani

sophister
26th April 2009, 07:34
Excuse me, what can we use these things to do??
Can we retrieve the position of the mouse out of the application interface??
Thanks