How to trigger a signal when "File" or any other menu is clicked?
-
-
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.
-
You could, but that sounds strange to say the least. What are you trying to achieve with this actually?
-
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.
-
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));
@ -
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.