Results 1 to 6 of 6

Thread: Closing out a animated context menu from any active screen

  1. #1
    Join Date
    Nov 2010
    Posts
    122
    Thanks
    62
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Smile Closing out a animated context menu from any active screen

    I have written an application in QtCreator using standard widgets and animation content where the GUI mimics very closely that of modern smartphones (i.e. kinectic scrolling lists, animated screen transitions, integrated editors, etc.). I have a sliding content menu similar to a modern smartphone based on the use of an external command button. I want to close out this menu whenever the user presses anywhere in the application area. Mouse clicks within the content menu are handled with a button selection. However, I need to also hide the content menu if the user presses the mouse anywhere in the application area. The application has a dozen or more screens which could be active at any time with the content menu. Some of these screens have additional nesting, such as context specific editors, with individual widgets. This is show in the sample attached screenshot.

    So my question is, what is the most efficient way of capture all mouse presses in the client area outside of the content menu itself. My preliminary implementation is to have each screen provide a signal within it's MousePress event, so the parent application can close out the content menu. However, I would prefer not having to implement this for each and every screen/form if there is a more efficient centralized way of doing it (from say the parent screen which contains the fixed header and footer components of the GUI).

    It there a better way of implementing this other than having to add a mousePressEvent() handler to each child screen (or perhaps having each screen/form derive from a common base class containing this feature?).

    Is there some form of mouse capture that can be performed when the context menu is made visible that could capture all mouse presses within the application, and then perhaps release this mouse capture upon menu closure. I need to eat the mouse press event outside the bounds of the context menu.

    Since mouse presses may be frequent, I would prefer not to have to signal for each one.
    Attached Images Attached Images

  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: Closing out a animated context menu from any active screen

    One way is to make the application serve as event filter for the widgets.
    So at creation time each widget installs the application event filter.
    Then you will need to be able to access the animated menu object (for its state, and to close it)(if nothing else works, a global), and in the event filter all you do is:
    if menu is visible AND event is a pressMouseEvent - you close the menu.
    You only need to subclass one class (QApplication) for the event filter, and add the installEventFilter() to each widget you are interested to be part of this behavior.
    ==========================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:

    bob2oneil (14th February 2011)

  4. #3
    Join Date
    Nov 2010
    Posts
    122
    Thanks
    62
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Closing out a animated context menu from any active screen

    Thanks high_flyer for your advice. I currentlly have custom event filters for many widgets, so I will have to see how this plays with an application level filter. Perhaps I can use the app level filter as the base class, and then specialize my custom event filters from it.

  5. #4
    Join Date
    Nov 2010
    Posts
    122
    Thanks
    62
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Closing out a animated context menu from any active screen

    It is possible to cascade event filters so that they to some extent act in series? I already have event filters in place for various widgets to implement kinetic scrolling, swipe navigation, etc.

  6. #5
    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: Closing out a animated context menu from any active screen

    It is possible to cascade event filters so that they to some extent act in series?
    Can you explain maybe with an example what do you mean?
    You can however ignore events, which then will be propagated further.
    ==========================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.

  7. #6
    Join Date
    Nov 2010
    Posts
    122
    Thanks
    62
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Closing out a animated context menu from any active screen

    Well, I have event filters for child windows similar to the following code segment. The Scroller() class provides an event filter on mouse events. So, could I reap the benefit of an application level event filter that applied to
    all windows, and yet have the behavior of a customized version (sort of a class derivation metaphor). I would also need windows that do not currently have event filters work with the application level event filter. I have noticed that
    for application windows/widgets which provide processing for mouse depressions (either through an event filter or an override of mousePressEvent()), the parent will not receive a mouse depression event if the child has a handler. I can always emit the signal to the parent, but for deeply nested content, I do not what to have this level of signals and slots to simply close out a context menu.

    Qt Code:
    1. // Set up scroller event filter
    2. m_scroller = new Scroller();
    3. ui->ProgramListWidget->viewport()->installEventFilter(m_scroller);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Context menu on tab
    By wolfi3b in forum Newbie
    Replies: 2
    Last Post: 18th October 2010, 17:35
  2. Detecting whether a context menu is currently active
    By Andrew Top in forum Qt Programming
    Replies: 0
    Last Post: 14th April 2010, 17:23
  3. Context menu
    By dejvis in forum Newbie
    Replies: 2
    Last Post: 20th September 2009, 22:02
  4. Qwt and context menu
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 9th December 2008, 08:55
  5. Context Menu
    By RY in forum Newbie
    Replies: 1
    Last Post: 10th September 2008, 07:59

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.