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

托盘

    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();
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容