美文网首页my-QT专栏
qt主窗口不在任务栏显示,在右下角托盘

qt主窗口不在任务栏显示,在右下角托盘

作者: c之气三段 | 来源:发表于2021-03-18 09:55 被阅读0次

托盘

    QSystemTrayIcon* qsys=new QSystemTrayIcon(this);
    qsys->setIcon(QIcon(":/titleCoin/Resources/bitbug_favicon.ico"));
    qsys->setToolTip(tr("柠檬"));
    QMenu* menu = new QMenu(this);
    QAction * actionWindow = new QAction("打开面板", this);
    menu->addAction(actionWindow);
    connect(actionWindow, &QAction::triggered, qw, &ShadowWindow::showNormal);//用要操作的窗口响应
    QAction *actionClose = new QAction("退出",this);
    menu->addAction(actionClose);
    connect(actionClose,&QAction::triggered,qw, &ShadowWindow::close);
    qsys->setContextMenu(menu);
    qsys->show();                   
    connect(qsys, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason)));//响应图标点击事件,要自定义槽函数。

槽函数

void PWindow::on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason reason) {
    if (reason == QSystemTrayIcon::Trigger) {
        qw->showNormal();
    }
}

隐藏任务栏图标

#include "stdafx.h"
#include "QtGuiApplication1.h"
#include <QtWidgets/QApplication>
#include "ShadowWindow.h"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QMainWindow window;
    ShadowWindow w(&window);//这样就可解决
    w.show();
    return a.exec();
}

相关文章

网友评论

    本文标题:qt主窗口不在任务栏显示,在右下角托盘

    本文链接:https://www.haomeiwen.com/subject/bvlucltx.html