#include <QSystemTrayIcon>
#include <QIcon>
#include <QLabel>
#include <QFileDialog>
#include <QFileIconProvider>
#include <QMessageBox>
#include <QFileInfo>
#include <QString>
#include "mainwindow.h"
#include "ui_mainwindow.h"
QString File="logo.png",notice=QString::fromLocal8Bit("提示"),say=QString::fromLocal8Bit("单击隐藏,双击显示");
QString Copyright=QString::fromLocal8Bit("Copyright zwc 版本:1.0.0");
MainWindow::MainWindow(QWidget *parent):QMainWindow(parent),ui(new Ui::MainWindow)
{
ui->setupUi(this);
// QLabel per=new QLabel(Copyright,this);
ui->statusBar->showMessage(Copyright);
QIcon systemIcon("logo.png");
myTrayIocn=new QSystemTrayIcon(systemIcon,this);
myTrayIocn->show();
myTrayIocn->showMessage(notice,say);
myTrayIocn->setContextMenu(ui->menu_F);
connect(myTrayIocn,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this,SLOT(activated(QSystemTrayIcon::ActivationReason)));
connect(ui->toolbtn,SIGNAL(clicked()),
this,SLOT(ClickedToolbtn()));
connect(ui->OKbtn,SIGNAL(clicked()),
this,SLOT(ClickOKbtn()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::ClickOKbtn()
{
QString lsfile=File;
File=ui->txt->text();
if(File==NULL) File=lsfile;
QIcon systemIco;
if(File[File.size()-1]=='e'){
QFileInfo file_info=File;
QFileIconProvider provider;
systemIco=provider.icon(file_info);
}
else if(File[File.size()-1]=='g'||File[File.size()-1]=='o'){
systemIco=QIcon(File);
}
else{
QMessageBox::information(this,"Wrong","File name problem!");
}
// myTrayIocn->~QSystemTrayIcon();
// myTrayIocn=new QSystemTrayIcon(systemIco,this);
// myTrayIocn->setContextMenu(ui->menu_F);
// myTrayIocn->show();
myTrayIocn->setIcon(systemIco);
this->hide();
myTrayIocn->showMessage(notice,say);
}
void MainWindow::ClickedToolbtn()
{
QString lsfile=File;
File=QFileDialog::getOpenFileName(this,tr("OpenFileDialog"),tr(":/"),QString("%1(*.png *.ico);;%2(*.exe)").arg(QString::fromLocal8Bit("图像")).arg(QString::fromLocal8Bit("应用陈序")));
if(File==NULL) File=lsfile;
ui->txt->setText(File);
/**/
//tr("图像(*.png);;应用程序(*.exe)")
}
void MainWindow::activated(QSystemTrayIcon::ActivationReason reason)
{
switch(reason)
{
case QSystemTrayIcon::Trigger:
this->hide();
break;
case QSystemTrayIcon::DoubleClick:
this->showNormal();
break;
default:break;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
系统托盘自定义图标工具(附C++源码)
共52个文件
dll:27个
qm:13个
cpp:2个
需积分: 22 9 下载量 185 浏览量
2018-03-24
16:14:51
上传
评论
收藏 16.11MB ZIP 举报
温馨提示
一个适合初学C++/Qt的人学习系统托盘技术的工程,内附源代码与编译好的程序,祝Qt学习道路越走越顺~
资源推荐
资源详情
资源评论
收起资源包目录
Tpicon_Instead.zip (52个子文件)
发布
Qt5Svg.dll 250KB
D3Dcompiler_46.dll 3.08MB
libGLESV2.dll 1.55MB
Qt5Widgets.dll 4.29MB
iconengines
qsvgicon.dll 30KB
Qt5Gui.dll 4.68MB
msvcr110.dll 842KB
Qt5Core.dll 4.45MB
msvcr110d.dll 1.6MB
libEGL.dll 11KB
platforms
qwindows.dll 981KB
msvcp110.dll 522KB
opengl32sw.dll 14.52MB
msvcp110d.dll 802KB
translations
qt_fi.qm 179KB
qt_cs.qm 179KB
qt_ca.qm 170KB
qt_lv.qm 175KB
qt_uk.qm 177KB
qt_sk.qm 177KB
qt_hu.qm 181KB
qt_ru.qm 177KB
qt_it.qm 184KB
qt_de.qm 191KB
qt_fr.qm 185KB
qt_ja.qm 152KB
qt_ko.qm 146KB
logo.png 53KB
vccorlib110.dll 246KB
Tpicon_Instead.exe 49KB
imageformats
qtga.dll 18KB
qgif.dll 24KB
qwebp.dll 317KB
qtiff.dll 306KB
qjp2.dll 409KB
qmng.dll 216KB
qwbmp.dll 18KB
qsvg.dll 19KB
qicns.dll 32KB
qdds.dll 38KB
qjpeg.dll 238KB
qico.dll 24KB
wintitleico.png 32KB
Tpicon_Instead
mainwindow.ui 4KB
Tpicon_Instead.pro.user 18KB
mainwindow.cpp 3KB
Tpicon_Instead.pro 449B
icon.ico 1KB
tpicon_instead.qrc 74B
main.cpp 275B
mainwindow.h 515B
res.rc 59B
共 52 条
- 1
资源评论
蒟蒻赵文川
- 粉丝: 10
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功