[SOLVED] Can't catch event

  • Hi All!
    I have @class MainWindow: public QMainWindow@ MainWindow has QSystemTrayIcon as member, in constructor MainWindow's i do @m_trayIcon.installEventFilter(this);@ and try catch the event at @protected: bool eventFilter(QObject *obj, QEvent *ev);@ in MainWindow, but nothing happens. I do this because need analyses some variables and set enable\disable some actions in ContextMenu, who's call at second mouse button click at tray icon. What i do wrong, and maybe some one know ease way to solve this problem?

  • Can you show body of your eventFilter method?

  • something like that:
    @bool eventFilter(QObject *obj, QEvent *ev){
    int someOperationForBreakpoint = 0; //hear i try to see breakpoint int debugger
    return __super::eventFilter(obj, ev);

    full code stay at work, and i can't show them from home.

  • QSystemTrayIcon is not a widget and therefore does not receive UI related events such as click events, show events, etc (That all handled by the OS, not Qt). You should use the "activated() signal":http://doc.qt.nokia.com/4.7-snapshot/qsystemtrayicon.html#activated instead.

  • Tnx, a lot!

  • I am having trouble capturing events in Ubuntu 17.04 Unity Desktop because of the following bug:


    The activated SIGNAL does not go out. I tried mouse click event capture and everything and nothing works. Is there a workaround?

  • Qt Champions 2018

    @anshah The bug you meantioned was fixed in Qt 5.4. Which Qt version do you use? Also which signals do not work for you?

  • @jsulm Wow thanks for responding. I'm using Ubuntu 17.04 with Qt 5.11 latest and I'm only seeing the activated signal not going out on the Unity desktop (Ubuntu default). The signal goes out fine on Plasma KDE and Gnome desktops. I just want to be able to click on the QSystemTrayIcon and have a window pop up and I can't even do that. Is there any workaround?

  • Qt Champions 2018

    @anshah Do you use Qt provided by Ubuntu?

  • @jsulm I installed Qt 5.11 on Ubuntu.

  • @jsulm I'll be happy if the QSystemTrayIcon can somehow capture mouse click events. It is not a QWidget so that has been difficult as well. What is happening is that both left/right clicks on Ubuntu Unity pop up a context menu. This is a known issue along with the activated signal not going out.

  • Lifetime Qt Champion

    Did you install Qt5.11 from Qt site or via apt-get ?
    I recall cases from other posters where vanilla Qt from Qt site would
    have issues with the Main Menus, but using the distro provided
    Qt would actually work as intended.

  • @mrjj It is definitely the vanilla Qt from the site. Let me uninstall and retry with apt-get. Thanks for the response!

  • I just installed Qt on Ubuntu using apt-get but apt-get only has 5.7 instead of 5.11.
    Different behavior:

    • icon shows up as blank in the system tray (triangle with exclamation in the middle)
    • Menu Item contains "Activate" because I updated sni-qt.conf

    It still doesn't solve my problem. I want the QSystemTrayIcon::activated to go out on left click or capture the left click somehow. I don't want to see an menu at all on left click.

Log in to reply

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