记录qt的一些案例,以后方便查找
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

56 lines
1.3 KiB

#include "widget.h"
#include "ui_widget.h"
#include "menudialog.h"
#include <QDebug>
#include <QPushButton>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QAction>
#include <QDebug>
#include <QWidgetAction>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
setWindowFlags(Qt::Tool);
CreateSystemTrayIcon(); //创建托盘
}
Widget::~Widget()
{
delete ui;
}
void Widget::CreateSystemTrayIcon()
{
QWidgetAction *pWdtAction = new QWidgetAction(this);
MenuDialog * menudialog = new MenuDialog();
pWdtAction->setDefaultWidget(menudialog);
//初始化菜单并添加项
QMenu* trayMenu = new QMenu(this);//菜单
trayMenu->addAction(pWdtAction);
//创建一个系统托盘
QSystemTrayIcon* trayIcon = new QSystemTrayIcon(this);
trayIcon->setIcon(QIcon("://app.ico")); //设置托盘图标
trayIcon->setToolTip("Shell_Notify"); //鼠标放上去显示的东东
trayIcon->setContextMenu(trayMenu); //设置菜单
trayIcon->show();
connect(trayIcon, &QSystemTrayIcon::activated, this, [=](QSystemTrayIcon::ActivationReason reason)
{
menudialog->uodateNumbers();
if( reason == 3){ //鼠标左键
trayIcon->contextMenu()->exec(QCursor::pos());
}
});
}