您现在的位置是:首页 >
企业资讯
带刷网ks赞 - 快手刷双击秒刷连接
时间:2024-04-28 19:22
评论
明白一个概念:托盘应用程序,本身应用程序并没有消失,只是隐藏;而托盘程序更像一个独立的小form存于托盘中。icon、tooltip、和一些功能。有了这些了解,就可以创建代码了上面是一些基本的操作。...
自助下单地址(拼多多砍价,ks/qq/dy赞等业务):点我进入
理解一个概念:托盘应用本身并没有消失,而是被隐藏了; 而托盘应用更像是一个独立的小表格,存放在托盘中。
引出要引入的类,QSystemTrayIcon; 具体功能是在托盘窗体中添加一些图标,tooltipsqt 托盘程序,以及一些功能。
有了这种理解qt 托盘程序,就可以创建代码
//菜单的创建
menu=new QMenu(this);
mExit=new QAction(QStringLiteral("退出"),this);
mShow=new QAction(QStringLiteral("显示主界面"),this);
connect(mShow,&QAction::triggered,this,&MainWindow::showForm);
connect(mExit,&QAction::triggered,this,&MainWindow::exitApp);
menu->addAction(mShow);
menu->addSeparator();
menu->addAction(mExit);
//托盘指示的创建
if (!QSystemTrayIcon::isSystemTrayAvailable())
{
QMessageBox::information(this,QStringLiteral("托盘提示"),QStringLiteral("不支持托盘"));
}
else
{
tray=new QSystemTrayIcon(this);
QIcon icon=QIcon("./hh_logo.ico");
tray->setIcon(icon);
tray->setToolTip(QStringLiteral("测试成功"));
tray->setContextMenu(menu);//关联菜单
connect(tray,&QSystemTrayIcon::activated,this,&MainWindow::activeForm);
}
}
void MainWindow::on_pushButton_clicked()
{//一个button按钮
this->close();
}
void MainWindow::closeEvent(QCloseEvent *event)
{//重写的窗口关闭事件
if (QMessageBox::information(this,QStringLiteral("关闭提示"),QStringLiteral("是否退出"),QMessageBox::Yes|QMessageBox::No)==QMessageBox::Yes)
event->accept();
else
{
event->ignore();
this->hide();
tray->show();
}
}
void MainWindow::exitApp()
{//退出程序
exit(0);
}
void MainWindow::showForm()
{//右键菜单的显示界面
this->show();
}
void MainWindow::activeForm(QSystemTrayIcon::ActivationReason reason)
{//对应的托盘信号 接收的槽函数
if (reason ==2)
this->show();
else
return;
}
以上是一些基本操作。