Intercepting user actions on whole application before processing events



  • Hi all,

    I want to intercept any action made by the user on application before the action be executed. The reason is that i have several views containing several tabs and so on ... and before the user can access another view he will be asked to save some data (if any) before leaving.

    I have one solution which works and consists to use filters installed on each view but i think that there's a solution more elegant but i didn't found it yet ...

    I've tried also to listen to focusChanged sent by QApplication by with no effects : the user can access a tab view and this signal is not emmited ...

    Any idea ?

    Thanks



  • As an alternative to the eventFilters you can catch several signals to detect that focus has changed.
    Like in your example with QTabWidget, you can connect to "currentChanged()":http://qt-project.org/doc/qt-5/qtabwidget.html#currentIndex-prop signal and process the focus changes there.



  • First, thanks for your reply.

    I've also connected currentChanged() signals to know which tab was clicked ... But the problem is not there !
    As i said in my first post, the current solution applied (and which works) use both the eventFilters and signals emitted by QTabWidget. I'm looking for a better solution because there is a lot of QTab and lot of views and thus lot of signals to connect and eventFilter to implement ...

    Let me take in example :

    Mainwindow contains :

    • Child Widget A which contains :

    QTabWidget with 5 tabs and each of them has 5 or 6 tabs and each tab of them has some input fields

    Some buttons outside of QTabWidget (which i'll call ButtonA-X)

    • Child Widget B which contains :

    QTabWidget with 7 tabs and each of them has 5 or 6 tabs and each tab of them has some input fields

    Some buttons outside of QTabWidget (which i'll call ButtonB-X)

    • Some buttons outside Child Widget A and Child Widget B (which i'll call ButtonB-Y)

    • and so one ...

    Imagine that the current view shown is the tab 3 of the tab 2 of Child Widget B and the user has entered some data. When he clicks on another tab, or one of ButtonB-X, or one of ButtonB-Y, he sould be asked to save data before showing the new tab. If he wants to save, the current view stays inchanged and the code for saving should be run (and some errors may occure) ...

    Actually, i've lot of signals connected and eventFilters implemented to heed all the possible situations ...

    Regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.