Search code examples
qtqt4

QSystemTray problems


I am trying to use QSystemTrayIcon for my application and i am facing some problems. It is the first time i use qt so i am not really used to it.

I followed this tutorial to make a system tray icon but i fail to customize it.

I want to have a button show/hide and not 3 show, hide, restore. These actions are really confusing for a newbie and i dont know what to do and what to connect.

I tried some things but with no luck.

Also when the system tray menu appears if you click somewhere else, the menu stays open. Any way to solve this thing too?


Solution

  • If you want to remove one of the menu items, modify the createTrayIcon function so that it only adds the actions you need (and clean up the unused members once you get it to work). It's that simple.

    If you want a single menu item or button to toggle between visible and hidden, you'll need to create a custom slot that calls show() or hide() (or setVisible(bool)) depending on whether the widget is hidden or not (use isVisible() for that for example). Then connect your action to that slot.

    Read the Signals and Slots documentation and examples for information about how to create a new slot.