Qt之系统托盘(QSystemTrayIcon详解)
? void TrayMenu::createActions()
? {
???? //創(chuàng)建托盤項(xiàng)
???? action_show = new QAction(this);
???? action_quit = new QAction(this);
???? action_login_home = new QAction(this);
???? action_help = new QAction(this);
???? action_about = new QAction(this);
???? action_check_update = new QAction(this);
???? action_setting = new QAction(this);
?
??? ?//設(shè)置托盤項(xiàng)圖標(biāo)
???? action_show->setIcon(QIcon(":/icon/open"));
??? ?action_login_home->setIcon(QIcon(":/icon/home"));
???? action_help->setIcon(QIcon(":/icon/help"));
???? action_about->setIcon(QIcon(":/icon/about"));
???? action_check_update->setIcon(QIcon(":/icon/update"));
???? action_setting->setIcon(QIcon(":/icon/set"));
???? action_quit->setIcon(QIcon(":/icon/quit"));
????
???? //設(shè)置托盤想文本
??? ?action_show->setText(QString("顯示"));
???? action_quit->setText(QString("退出"));
???? action_login_home->setText(QString("登錄網(wǎng)頁(yè)"));
???? action_help->setText(QString("幫助"));
???? action_about->setText(QString("關(guān)于"));
???? action_check_update->setText(QString("檢查更新"));
???? action_setting->setText(QString("設(shè)置"));
?
???? //添加菜單項(xiàng)
???? this->addAction(action_show);
???? this->addAction(action_setting);
???? this->addAction(action_login_home);
???? this->addSeparator();
???? this->addAction(action_help);
???? this->addAction(action_about);
???? this->addAction(action_check_update);
???? this->addSeparator();
???? this->addAction(action_quit);
???? action_setting->setVisible(false);
?
??? ?//設(shè)置信號(hào)連接(這里僅列舉連接顯示窗口的信號(hào))
???? QObject::connect(action_show, SIGNAL(triggered(bool)), this, SIGNAL(showWidget()));
?}
?
? LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent)
? {
???? QSystemTrayIcon *system_tray = new QSystemTrayIcon();
???? //放在托盤提示信息、托盤圖標(biāo)
???? system_tray ->setToolTip(QString("我就是托盤"));
?????system_tray ->setIcon(QIcon(":/icon/login"));
???? TrayMenu *tray_menu = new TrayMenu();
???? system_tray->setContextMenu(tray_menu);
???? //點(diǎn)擊托盤執(zhí)行的事件
? ? ? connect(system_tray?, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconIsActived(QSystemTrayIcon::ActivationReason)));
? ? ?connect(tray_menu, SIGNAL(showWidget()), this, SLOT(showNormal()));
???? //顯示托盤
???? system_tray->show();
??? //托盤顯示提示信息
??? system_tray->showMessage(QString("托盤標(biāo)題"), QString("托盤顯示內(nèi)容"));
? }
?
? void LoginDialog::iconIsActived(QSystemTrayIcon::ActivationReason reason)
? {
???? switch(reason)
???? {
???? //點(diǎn)擊托盤顯示窗口
???? case QSystemTrayIcon::Trigger:
????? {
??????? showNormal();
??????? break;
????? }???
??? ?//雙擊托盤顯示窗口
???? case QSystemTrayIcon::DoubleClick:
???? {
?????? showNormal();
?????? break;?
?????}????????????
???? default:
????? break;
???? }
? }
?
? OK,這樣我們的托盤功能就Over了!
總結(jié)
以上是生活随笔為你收集整理的Qt之系统托盘(QSystemTrayIcon详解)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 关于 mybatis-generator
- 下一篇: linux 32bit 改为64bit