Results 1 to 7 of 7

Thread: create mouse click event problem

  1. #1
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default create mouse click event problem

    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 :

    Qt Code:
    1. QMouseEvent event(QEvent::MouseButtonPress, cursor.pos(), Qt::LeftButton, 0, 0);
    2. event.setAccepted(true);
    3. QApplication::sendEvent(this, &event);
    To copy to clipboard, switch view to plain text mode 

    That code did not work. Any idea why?

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: create mouse click event problem

    What do want by sending a mouse click event like this ?

  3. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: create mouse click event problem

    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.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  4. #4
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: create mouse click event problem

    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 ..

  5. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: create mouse click event problem

    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.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  6. The following user says thank you to faldzip for this useful post:

    yagabey (8th October 2009)

  7. #6
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: create mouse click event problem

    Is there a good method to find what widget under cursor?

  8. #7
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: create mouse click event problem

    Quote Originally Posted by yagabey View Post
    Is there a good method to find what widget under cursor?
    ok ,i think
    Qt Code:
    1. QWidget * QWidget::childAt ( int x, int y ) const
    To copy to clipboard, switch view to plain text mode 
    may work.

Similar Threads

  1. Replies: 2
    Last Post: 4th August 2008, 07:44
  2. Replies: 7
    Last Post: 20th November 2007, 12:15
  3. Create new an event, help me?
    By dungsivn in forum Qt Programming
    Replies: 6
    Last Post: 4th July 2007, 11:22
  4. event problem
    By windkracht8 in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2006, 11:52
  5. mouse click event
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 1st May 2006, 09:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.