本文主要是介绍Qt托盘实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
实现比较简单, 值得注意的是在main函数中设置app.setQuitOnLastWindowClosed(false);
class WeatherTrayIcon : public QSystemTrayIcon
{Q_OBJECTpublic:explicit WeatherTrayIcon(QObject *parent = NULL);~WeatherTrayIcon();private:private slots:void SlotIconActivate(QSystemTrayIcon::ActivationReason reason);private:};
WeatherTrayIcon::WeatherTrayIcon(QObject *parent): QSystemTrayIcon(parent)
{setIcon(QIcon(":/WeatherTrayIcon/Resources/icon.jpg"));setToolTip("TurboAudit");connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(SlotIconActivate(QSystemTrayIcon::ActivationReason)));
}WeatherTrayIcon::~WeatherTrayIcon()
{}void WeatherTrayIcon::SlotIconActivate( QSystemTrayIcon::ActivationReason reason )
{switch (reason){case QSystemTrayIcon::Trigger:case QSystemTrayIcon::DoubleClick:// 显示主窗体//w->show();break;case QSystemTrayIcon::Context:// 显示菜单{QRect rect = geometry();QRect menuRect;menuRect.setLeft(rect.right());menuRect.setTop(rect.y()-200);menuRect.setWidth(100);menuRect.setHeight(200);QWidget *w = new QWidget;w->setGeometry(menuRect);w->show();} break;default:;}}
这篇关于Qt托盘实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!