On the "more advanced view" I can't help, however I recently implemented a tray icon application.
void Launcher::InitializeTrayIcon() {
CreateTrayActions();
CreateTrayIcon();
}
void Launcher::CreateTrayActions() {
restoreAction = new QAction(tr("&Restore"), this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
openConfig = new QAction(tr("&Open Configuration"), this);
connect(openConfig, SIGNAL(triggered()), this, SLOT(openConfigFile()));
languageSelection = new QMenu(tr("Select Language"), this);
QIcon englishFlag(":/Resources/FlagEnglish.png");
activateEnglishLanguage = new QAction(englishFlag, tr("English"), this);
connect(activateEnglishLanguage, SIGNAL(triggered()), this,
SLOT(changeLanguageToEnglish()));
QIcon germanFlag(":/Resources/FlagGerman.png");
activateGermanLanguage = new QAction(germanFlag, tr("German"), this);
connect(activateGermanLanguage, SIGNAL(triggered()), this,
SLOT(changeLanguageToGerman()));
}
void Launcher::CreateTrayIcon() {
// Create Menu for Tray Icon
trayIconMenu = new QMenu(this);
languageSelection = trayIconMenu->addMenu(tr("Select Language"));
languageSelection->addAction(activateEnglishLanguage);
languageSelection->addAction(activateGermanLanguage);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addAction(openConfig);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
// Create tray icon by passing its Menu
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
// Add functionality on double click
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
SetTrayIconLogo();
trayIcon->show();
}
void Launcher::SetTrayIconLogo() {
QIcon icon(":/Resources/icon.ico");
trayIcon->setIcon(icon);
}
Note that in order not to close the complete application when you click the "close" icon in the window, you have to overwrite the close event:
void Launcher::closeEvent(QCloseEvent *event) {
hide();
event->ignore();
}
Hope this helps.