Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to trigger a signal when "File" or any other menu is clicked?
Forum Updated to NodeBB v4.3 + New Features

How to trigger a signal when "File" or any other menu is clicked?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 1.6k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sasmaster
    wrote on last edited by
    #1

    Hi All.I need to trigger an event when "File" menu is clicked" .Not the sub-menus which I can trigger via action but the menu itself. I have tried :

    @
    connect(m_fileMenu,SIGNAL(triggered(QAction*)),this,SLOT(MenuClickSlot(QAction*)) );
    @

    Doesn't work.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Clicking on a menu either shows it or hides it. There is no underlying action so there is no triggered() signal. You can connect to signals aboutToShow() and aboutToHide() to detect when it was clicked.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sasmaster
        wrote on last edited by
        #3

        Can't I detect a click in the area of the whole menu bar? Or even better,can I detect a click on a whole area of the main window?Including any content it has got inside it?

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You could, but that sounds strange to say the least. What are you trying to achieve with this actually?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sasmaster
            wrote on last edited by
            #5

            Are you familiar with Adobe AfterEffects ? I am working on a program which should have similar interaction functionality.For example in AE if you click play the preview,it starts playing,but once you click somewhere inside the IDE the playback stops.That's what I want to have in my app.Thanks.

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Ok, sounds like entirely different problem. The easiest would be to install event filter on the application object:

              @
              class ClickHandler : public QObject {
              public:
              ClickHandler(QObject* parent) : QObject(parent) {}
              bool eventFilter(QObject * obj, QEvent * event) {
              if(event->type() == QEvent::MouseButtonRelease)
              //Do stuff
              return false;
              }
              };

              //somewhere:
              qApp->installEventFilter(new ClickHandler(qApp));
              @

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sasmaster
                wrote on last edited by
                #7

                Ok,thanks for that.One more question.Will it override the event of the objects under the click?For instance,if the click location falls on a button?

                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  No, filters do not override anything. They just allow you to block some events from reaching their target object. They do not replace the functionality implemented in that object's event handler (ok, they can if you block the event and handle it in the filter but you get the point).
                  Blocking is done by returning true from the eventFilter method, but since in this case we don't want to block anything, just react to some of the events, we always return false.

                  1 Reply Last reply
                  0

                  • Login

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