Results 1 to 4 of 4

Thread: QEvent::MouseButtonRelease with QEvent::Leave

  1. #1
    Join Date
    Jul 2017
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QEvent::MouseButtonRelease with QEvent::Leave

    I have multiple widgets for which I want to implement the following functionality:

    If the mouse hovers away from the widget, and then a mouse click occurs anywhere outside the widget , then I have an animation that hides the widget(s).

    I am trying to figure out how to have two subsequent events be captured and handled in the simplest, most efficient way. I believe I'd need to use a combination of QEvent::MouseButtonRelease with QEvent::Leave but

    I'm just not sure how to synchronize both since each event will be received at its own time in my event filter. So for the second event QEvent::MouseButtonRelease, how can we know when that event is handled that a previous event QEvent::Leave

    has just occured to get the desired behaviour?

    I am also open to any other methods that are more ideal to solving this problem.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QEvent::MouseButtonRelease with QEvent::Leave

    If the mouse hovers away from the widget, and then a mouse click occurs anywhere outside the widget , then I have an animation that hides the widget(s).
    This description is not very clear as it leaves open questions:
    Hovering over widgets is something you generally do when the mouse moves on the screen.
    So chances are that a situation where the mouse has hovered away from a widget it usually present - unless your application window opened not under the mouse pointer, and you have not yet moved the mouse over your application window.
    This in turn means that usually any click will mean hiding the widgets.
    More over, what if you hover over one widgets, leave it, hover over another widget and leave that as well, and then click somewhere.
    Should both hovered and left widgets be hidden?

    For the sake of simplicity I will assume that the answer is yes, that for each hovered and left widget when an "external" click occurs they all should be hidden.
    One way to implement it would be to "register" each widget which gets a leave event (say, add its pointer to a list) and then in the mouse release event simply go over that list and call hide() on the elements in that list (and then empty the list).
    More details on your part might change that answer however.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    qtstarter121 (1st August 2017)

  4. #3
    Join Date
    Jul 2017
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QEvent::MouseButtonRelease with QEvent::Leave

    Thank you for your insightful response. I apologize for the lack of clarity. The situation is as follows:

    Note: My process of hiding/showing widgets is not by actually hiding/showing them , but rather it is a sliding animation of the positions of these widgets.

    This is how it should work:

    1) My mouse hovers to edges of the screen : left, right top, bottom, and consequently a widget "shows" up.
    2) Leaving this widget and subsequently entering a second widget by hovering over to another screen edge should result in the previous widget to be "hidden" ( this is without clicking anywhere outside ).
    3) Otherwise if you do not enter a second widget and simply click outside the widget somewhere, then that widget should "hide".

    Based on this, I attempted a solution by registering the most recently left widget, and hiding it when a second widget is entered or when an external mouse click occurs.

    I am having some difficulty where my hiding animation does not take place if I hover to an edge and a widget appears, and I click outside ( so as in case 3) above) , but rather the widget actually hides instead due to loss of focus because I have clicked inside the widget before clicking elsewhere. If I do not give my widget focus before clicking elsewhere then my hiding animation occurs correctly.

    I believe I would need to override the functionality where a widget is hidden due to loss of focus and replace that code with my hiding animation. Would you be able to help me figure out what to do to achieve this?


    Added after 1 50 minutes:


    I read that I could override QWidget::focusOutEvent(QFocusEvent *event) for my object but the problem is that there is no separate class implementation for the widgets I need to "hide" so I think I would to somehow override
    this event in my eventFilter of my QMainWindow which all the widgets are loaded into. Any help would be appreciated
    Last edited by qtstarter121; 1st August 2017 at 22:26.

  5. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QEvent::MouseButtonRelease with QEvent::Leave

    I read that I could override QWidget::focusOutEvent(QFocusEvent *event) for my object but the problem is that there is no separate class implementation for the widgets I need to "hide"
    What is the problem with sub classing QWidget to allow the functionality you need?
    I think I would to somehow override this event in my eventFilter of my QMainWindow which all the widgets are loaded into.
    That too is an approach that could work.
    It is not as clean as sub classing, but it can work.

    Any help would be appreciated
    Not sure help with what?
    It would help if you point to what it is you need help with.
    Do you need help with using eventFilter()? With subclassing?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. QEvent::ApplicationDeactivate
    By migel in forum Newbie
    Replies: 1
    Last Post: 23rd April 2012, 07:54
  2. how to use qevent?
    By cic in forum Qt Programming
    Replies: 1
    Last Post: 9th December 2011, 09:30
  3. How do I use QEvent?
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 2nd September 2011, 10:37
  4. QEvent problem
    By batileon in forum Qt Programming
    Replies: 3
    Last Post: 4th May 2009, 12:23
  5. QEvent::Enter
    By incapacitant in forum Newbie
    Replies: 6
    Last Post: 22nd March 2006, 08:07

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.