Results 1 to 2 of 2

Thread: Defining widget regions sensitive to mouse events?

  1. #1
    Join Date
    Oct 2009
    Posts
    33
    Thanks
    2

    Default Defining widget regions sensitive to mouse events?

    Hey,

    I have a main window that consists of several widgets stacked on top of each other. The widgets are different shapes and do not visually block each other, so you can see them all separately, however they do overlap. How can I let mouse events actually go to their corresponding widgets? As it stands right now, the top most widget captures all events. I think this makes sense since the widgets technically have the same outer rect(), based on the main window.

    So specifically, whereas something like setAttribute(Qt::WA_TransparentForMouseEvents) would make an entire widget receive no mouse events, how can I have a defined region for each widget to receive mouse event, instead of having the whole rect() of the widget be sensitive to events?

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

    Default Re: Defining widget regions sensitive to mouse events?

    If sibling widgets overlap then this is a misdesign of the UI. If you want to stack widgets then really stack them - make one a parent of the other. Otherwise it's not possible to propagate events properly as for widgets the events propagate from the child to the parent (and since a widget can have only one parent, if it overlaps some of its siblings, siblings won't receive the events). Once you do that, reimplement mouse event handlers for your widgets and ignore() the events when they happen in regions you consider transparent for a particular widget. Then the event propagation mechanism will kick in and forward the event to the parent.

    Alternatively implement your UI in Graphics View which is probably a better choice here if you really need overlapping items. Event propagation for graphics item is different than for widgets -- there events propagate to items that are "under" the item currently handling the event in the point where the event happens. Moreover graphics items are empty by default so defining shape() properly will immediately get you the behaviour you want.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    kachofool (29th December 2010)

Similar Threads

  1. Replies: 2
    Last Post: 21st June 2009, 06:04
  2. Determining when mouse over widget without events
    By Kimmo in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2007, 10:48
  3. Handling Mouse Events of a parent widget
    By dvmorris in forum Qt Programming
    Replies: 2
    Last Post: 28th March 2007, 18:44
  4. Mouse Events in a widget
    By Rayven in forum Qt Programming
    Replies: 2
    Last Post: 5th May 2006, 14:07
  5. Forwarding mouse events to another widget.
    By yogeshm02 in forum Qt Programming
    Replies: 8
    Last Post: 28th February 2006, 13: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.