Results 1 to 4 of 4

Thread: Mouse Events

  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Mouse Events

    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:

    Qt Code:
    1. void GLWidget::mousePressEvent(QMouseEvent *event)
    2. {
    3. lastPos = event->pos();
    4. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Mouse Events

    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.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Mouse Events

    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?

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Mouse Events

    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.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 3
    Last Post: 8th October 2011, 09:46
  2. Mouse events
    By Maluko_Da_Tola in forum Newbie
    Replies: 3
    Last Post: 25th August 2010, 06:55
  3. Mouse Events
    By daviddoria in forum Qt Programming
    Replies: 6
    Last Post: 13th May 2008, 11:55
  4. mouse events
    By xyzt in forum Newbie
    Replies: 3
    Last Post: 23rd March 2008, 11:14
  5. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 06:13

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.