Results 1 to 9 of 9

Thread: Forwarding mouse events to another widget.

  1. #1
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Cool Forwarding mouse events to another widget.

    Hi

    I have two widgets A & B, A is shown above B. I want that widget B forward all mouse events to widget B. Can this be done? Hints please.

    Oops, looks like I have presented to you a very simplified version of my problem. Actually, I have a stack of widgets and the top most widget which receives mouse events must forward this event to the top-most widget (at a given mouse position) under this widget. Got it?

    With regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Forwarding mouse events to another widget.

    Try event filters.

  3. #3
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Forwarding mouse events to another widget.

    Quote Originally Posted by jacek
    Try event filters.
    The problem is how to find the top-most widget under the current widget. (That too quickly, as even mouse move events will be forwarded with mouse tracking on)

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Forwarding mouse events to another widget.

    Does "under" represent a geometry or parent-child relation?

  5. #5
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Forwarding mouse events to another widget.

    Quote Originally Posted by wysota
    Does "under" represent a geometry or parent-child relation?
    I need to manipulate it in geometry, but they must be a part of single top-level window.

    I am working on a skinnable interface in which I have an widget named GLayer which displays any image with alpha content so that the contents of widgets below it are seen through i.e. GLayer does not do anything and needs to forward events meant for the widgets below to the respective widget.

    Two screenshots attached, one with and other without GLayer, will help you understand.
    Attached Images Attached Images

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Forwarding mouse events to another widget.

    Ok... so keep a list of all widgets (QObjectList for example) and iterate through that list checking each ones coordinates until you find the one that fits you most.

  7. #7
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation Re: Forwarding mouse events to another widget.

    Quote Originally Posted by wysota
    Ok... so keep a list of all widgets (QObjectList for example) and iterate through that list checking each ones coordinates until you find the one that fits you most.
    I load all data from a xml file so I already have a list of all top level widgets as well as all widgets. It can easily be found which widget lies in the area, but seems that finding one which is one-step down from the top is tricky.

    EDIT: -
    QApplication has following method:

    QWidget * widgetAt ( const QPoint & point )

    Even this seems to return top most widget having the given point.
    Last edited by yogeshm02; 27th February 2006 at 14:08.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Forwarding mouse events to another widget.

    Maybe you could just draw that pixmap without using the GLayer widget?

  9. #9
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation Re: Forwarding mouse events to another widget.

    Quote Originally Posted by jacek
    Maybe you could just draw that pixmap without using the GLayer widget?
    Now, that would be extremely difficult to manage as the interface is being designed to be skinnable as well as scriptable.
    I've two rough ideas in my mind which ill try out.

    Two important points to notice are:-
    1. Widget which is initialised last is always at the top (Could not found any proof for this, just observation)
    2. As i've a scriptable interface, i am providing wrappers to all the custom widgets, so I can use them to monitor any changes in the z-order.

Similar Threads

  1. QGraphicsView Mouse Events
    By tomf in forum Qt Programming
    Replies: 5
    Last Post: 29th July 2008, 15:03
  2. pass mouse event information to another widget
    By Rooster in forum Qt Programming
    Replies: 5
    Last Post: 12th July 2008, 04:23
  3. Determining when mouse over widget without events
    By Kimmo in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2007, 10:48
  4. Handling Mouse Events of a parent widget
    By dvmorris in forum Qt Programming
    Replies: 2
    Last Post: 28th March 2007, 18:44
  5. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 19:25

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.