☆Smoozer☆

::Easy Life.
如何显示system tray icon

int main(int argc, char *argv[])
{
  QApplication app(argc, argv);

  ...

  tabwidget_ui_demo w; // main window
  QObject::connect(&w, SIGNAL(sigbtnQuitClicked()), &app, SLOT(quit()));
  w.show(); // show main window

  QSystemTrayIcon sysTray; // system tray icon
  sysTray.setIcon(QIcon("images/favorites.png"));


  QMenu *menu = new QMenu; // create context menu
  QAction *actionAbout = new QAction("About QT4", 0); // create one action
  QObject::connect(actionAbout, SIGNAL(triggered()), &app, SLOT(aboutQt()));
  menu->addAction(actionAbout); // add the action to menu

  QAction *actionShow = new QAction("Pop Up", 0);
  QObject::connect(actionShow, SIGNAL(triggered()), &w, SLOT(showMaximized()));
  menu->addAction(actionShow);

  QAction *actionExit = new QAction("Exit", 0);
  QObject::connect(actionExit, SIGNAL(triggered()), &app, SLOT(quit()));
  menu->addAction(actionExit);

  sysTray.setContextMenu(menu);
  sysTray.show(); // show system tray

  return app.exec();

}

 

运行结果如图:

posted on 2009-05-19 18:01  smoozer  阅读(2156)  评论(0编辑  收藏  举报