PDA

View Full Version : create mouse click event problem



yagabey
8th October 2009, 08:54
Hello,
I am trying to handle data coming from a touchscreen monitor. I can set the mouse cursor position with "setPos()" function according to x and y position data. But i couldn' t create a left click event :


QMouseEvent event(QEvent::MouseButtonPress, cursor.pos(), Qt::LeftButton, 0, 0);
event.setAccepted(true);
QApplication::sendEvent(this, &event);

That code did not work. Any idea why?

yogeshgokul
8th October 2009, 13:12
What do want by sending a mouse click event like this ?

faldzip
8th October 2009, 14:23
events are passed from childrens to parents, not from parents to childrens, so if you want to send click to some button, you have to send it directly to that button, not to applicattion which has this button. Application would be the last object trying to handle this event when any children and children of children and so on (but starting from the deepest nested children) can't handle it for their own.

yagabey
8th October 2009, 15:11
I dont want to send "click" to a spesific widget; I want to send it to the "point" under mouse cursor. When someone clicks on the touch screen, i should simulate that click on the gui. So actually the application should handle the click, i think ..

faldzip
8th October 2009, 15:34
no, you have to find what widget is at that point and send event to that widget. If it is for example a button in a groupbox you can't send it to that groupbox and want the button to be pressed because group box will send thes event to the window it is in. Events are propagating from childrens to parent, so the main windows is a parent (grand parent and so on...) for all other widgets in it, so sending event to the main windows won't make any sense because it will try to handle it as a main window (no passing to any children) and discards it on a failure.

yagabey
8th October 2009, 15:41
Is there a good method to find what widget under cursor?

yagabey
8th October 2009, 22:45
Is there a good method to find what widget under cursor?

ok ,i think
QWidget * QWidget::childAt ( int x, int y ) const may work.