This is on the constructor:
Qt Code:
  1. trayIcon = new QSystemTrayIcon(this);
  2. trayIcon->setIcon(QIcon(":/icons/omg4.png"));
  3. trayIcon->setToolTip("Wallpaper Changer \nDouble click to show the window.\nMiddle click to exit the application.\nRight click for some options.");
  4. connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(clickSysTrayIcon(QSystemTrayIcon::ActivationReason)));
  5. connect(this,SIGNAL(minimized()),this,SLOT(hide()),Qt::QueuedConnection);
  6. QMenu *clock_menu = new QMenu;
  7. //clock_menu->addAction("&Play",this,SLOT(playClicked()));
  8. //clock_menu->addAction("P&ause",this,SLOT(pauseClicked()));
  9. //clock_menu->addAction("St&op",this,SLOT(stopClicked()));
  10. clock_menu->addAction("&Show",this,SLOT(showClicked()));
  11. clock_menu->addAction("Se&ttings",this,SLOT(showSettings()));
  12. clock_menu->addAction(QIcon(":/new/clock/clock.png"),"&About",this,SLOT(showAbout()));
  13. clock_menu->addSeparator();
  14. clock_menu->addAction("&Exit",qApp,SLOT(quit()));
  15. trayIcon->setContextMenu(clock_menu);
To copy to clipboard, switch view to plain text mode 
This on the change event:
Qt Code:
  1. switch (e->type()) {
  2. case QEvent::LanguageChange:
  3. ui->retranslateUi(this);
  4. break;
  5.  
  6. //see if the event is changing the window state
  7. case QEvent::WindowStateChange:
  8. //if it is, we need to see that this event is minimize
  9.  
  10. if (isMinimized()) {
  11. //EDWWWWWWWW
  12. trayIcon->show();
  13. // QCoreApplication::sendPostedEvents(QObject *trayIcon);
  14. enum MessageIcon { NoIcon, Information, Warning, Critical };
  15. QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(Information);
  16.  
  17. trayIcon->showMessage("titlos", "mplampla", icon, 10000);
  18. emit minimized();}
  19.  
  20. default:
  21. break;
  22.  
  23. QMainWindow::changeEvent(e); }
To copy to clipboard, switch view to plain text mode 
And this is the void function while it is minimized:
Qt Code:
  1. void MainWindow::clickSysTrayIcon(QSystemTrayIcon::ActivationReason reason)
  2. {
  3. //reason is a variable that holds the type of activation or click done on the icon tray
  4. switch (reason) {
  5. case QSystemTrayIcon::DoubleClick: //if it's a double click
  6. //hide the icon
  7. trayIcon->hide();
  8. //show the main window
  9. this->showNormal();
  10. break;
  11. case QSystemTrayIcon::MiddleClick:
  12. //quit the application
  13. qApp->quit();
  14. break;
  15. case QSystemTrayIcon::Unknown:
  16. break;
  17. case QSystemTrayIcon::Context:
  18. break;
  19. case QSystemTrayIcon::Trigger:
  20. break;
  21. default :
  22. ;
  23. }
  24. }
To copy to clipboard, switch view to plain text mode 
I don't know why but the message is shown on the left and not below the application's icon. Why is this happening and how can I fix it?