I made a program with QSystemTrayIcon some months ago.
Here my code. It isn't full, I simplified it.
header:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSystemTrayIcon>
#include <QNetworkReply>
#include "mythread.h"
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
void createActions();
void createTrayIcon();
public slots:
void ment();
};
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSystemTrayIcon>
#include <QNetworkReply>
#include "mythread.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
void createActions();
void createTrayIcon();
QAction *quitAction;
QAction *settingsAction;
QSystemTrayIcon *trayIcon;
QMenu *trayIconMenu;
public slots:
void ment();
};
To copy to clipboard, switch view to plain text mode
code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QNetworkRequest>
#include <QNetworkAccessManager>
#include <QMenu>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
createActions();
createTrayIcon();
ui->setupUi(this);
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(ment()));
trayIcon->show();
}
MainWindow::~MainWindow(){
mt->exit();
mt->wait();
delete ui;
}
void MainWindow::createActions(){
quitAction
= new QAction(tr
("&Kilepes"),
this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
settingsAction
= new QAction(tr
("&Beallitasok"),
this);
connect(settingsAction, SIGNAL(triggered()), this, SLOT(showNormal()));
}
void MainWindow::createTrayIcon(){
trayIconMenu
= new QMenu(this);
trayIconMenu->addAction(settingsAction);
trayIconMenu->addAction(quitAction);
trayIcon->setContextMenu(trayIconMenu);
QIcon icon
(":/images/ok.svg");
trayIcon->setIcon(icon);
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QNetworkRequest>
#include <QNetworkAccessManager>
#include <QMenu>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
createActions();
createTrayIcon();
ui->setupUi(this);
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(ment()));
trayIcon->show();
}
MainWindow::~MainWindow(){
mt->exit();
mt->wait();
delete ui;
}
void MainWindow::createActions(){
quitAction = new QAction(tr("&Kilepes"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
settingsAction = new QAction(tr("&Beallitasok"), this);
connect(settingsAction, SIGNAL(triggered()), this, SLOT(showNormal()));
}
void MainWindow::createTrayIcon(){
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(settingsAction);
trayIconMenu->addAction(quitAction);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
QIcon icon(":/images/ok.svg");
trayIcon->setIcon(icon);
}
To copy to clipboard, switch view to plain text mode
Bookmarks