Qt将程序最小角化到系统托盘
#include "test.h" #include "QPushButton" #include <QSystemTrayIcon> Test::Test(QWidget *parent) : QWidget(parent) { ui.setupUi(this); QPushButton* btn = new QPushButton(QString::fromLocal8Bit("最小化"), this); connect(btn, &QPushButton::clicked, this, [=]() { this->hide(); /* 最小化到系统托盘 */ QSystemTrayIcon* mSysTrayIcon = new QSystemTrayIcon(this); mSysTrayIcon->setIcon(QIcon("logo.png")); mSysTrayIcon->setToolTip(QString::fromLocal8Bit("测试系统托盘图标")); mSysTrayIcon->show(); // 在系统托盘上显示此对象 }); }