Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Contextual Menu in QML and Widget !

Contextual Menu in QML and Widget !

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlcontextualmenuwidgetqquickwidget
3 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Renaud G.
    wrote on 20 Oct 2018, 23:51 last edited by
    #1

    Hi all,

    In my application, I have QQuickWidget which displays QML (obviously).
    QML code is generated and my users can amend it.

    Some QML items required a contextual menu. So, I added Menu and MenuItem in the qml generator.
    It works fine but I also need to display contextual menu to manage the view. This contextual menu is managed in QWidget side.
    I tried to install an event filter on the root item or the QQuickWidget or QQuickWindow to be notify on Contextual Event.

    I can't reach the wanted behaviour.
    Basically I want to display the QML contextual menu if the item under the mouse has one and when the qml has no contextual menu then displays the QWidget managed one.

    The only behaviour I got:
    The QWidget contextual menu every where, even over the QML Item which has its own contextual menu.
    If i disable all event filters I get my QML menu but of course no QWidget menu.

    Is there a way to do that ?
    I don't want to traverse all QML item tree to find if there are items with Contextual menu.
    Because, my generated code has item with contextual menu but my user may add contextual menu as wheel if they want.

    Thank you
    Regards

    Rolisteam: RPG virtual tabletop software in Qt: www.rolisteam.org : https://github.com/Rolisteam/rolisteam
    Github: https://github.com/obiwankennedy

    R 1 Reply Last reply 22 Oct 2018, 06:59
    0
    • R Renaud G.
      20 Oct 2018, 23:51

      Hi all,

      In my application, I have QQuickWidget which displays QML (obviously).
      QML code is generated and my users can amend it.

      Some QML items required a contextual menu. So, I added Menu and MenuItem in the qml generator.
      It works fine but I also need to display contextual menu to manage the view. This contextual menu is managed in QWidget side.
      I tried to install an event filter on the root item or the QQuickWidget or QQuickWindow to be notify on Contextual Event.

      I can't reach the wanted behaviour.
      Basically I want to display the QML contextual menu if the item under the mouse has one and when the qml has no contextual menu then displays the QWidget managed one.

      The only behaviour I got:
      The QWidget contextual menu every where, even over the QML Item which has its own contextual menu.
      If i disable all event filters I get my QML menu but of course no QWidget menu.

      Is there a way to do that ?
      I don't want to traverse all QML item tree to find if there are items with Contextual menu.
      Because, my generated code has item with contextual menu but my user may add contextual menu as wheel if they want.

      Thank you
      Regards

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 22 Oct 2018, 06:59 last edited by
      #2

      @Renaud-G. said in Contextual Menu in QML and Widget !:

      If i disable all event filters I get my QML menu but of course no QWidget menu.

      event filters are executed BEFORE delivering the event to the target object/widget.

      How exactly are you showing the context menu in QML?

      An approach could be (i dont't know if this works for sure) to subclass QQuickView, override mosuePressEvent / mouseReleaseEvent, call the base class implementation first and check if the mouse event was accepted. If not show the widget context menu.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      R 1 Reply Last reply 25 Oct 2018, 09:05
      0
      • R raven-worx
        22 Oct 2018, 06:59

        @Renaud-G. said in Contextual Menu in QML and Widget !:

        If i disable all event filters I get my QML menu but of course no QWidget menu.

        event filters are executed BEFORE delivering the event to the target object/widget.

        How exactly are you showing the context menu in QML?

        An approach could be (i dont't know if this works for sure) to subclass QQuickView, override mosuePressEvent / mouseReleaseEvent, call the base class implementation first and check if the mouse event was accepted. If not show the widget context menu.

        R Offline
        R Offline
        Renaud G.
        wrote on 25 Oct 2018, 09:05 last edited by
        #3

        @raven-worx Thanks, I will try that. I let you know if it works or not.

        Rolisteam: RPG virtual tabletop software in Qt: www.rolisteam.org : https://github.com/Rolisteam/rolisteam
        Github: https://github.com/obiwankennedy

        1 Reply Last reply
        0

        2/3

        22 Oct 2018, 06:59

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved