C++ (Qt)QAction* connectionMenuItem = new QAction( trayIconMenu->addAction( QIcon( ":/connect.png" ), "Подключиться", parent, SLOT( connectToHipchatWithFileData() ) ) );
C++ (Qt)connectionMenuItem->setText( "Отключиться" );
C++ (Qt)QAction* connectionMenuItem = trayIconMenu->addAction( QIcon( ":/connect.png" ), "Подключиться", parent, SLOT( connectToHipchatWithFileData() ));
C++ (Qt)#include <QMainWindow>#include <QSystemTrayIcon> class MainWindow : public QMainWindow{ Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); private slots: void messageReceived(QSystemTrayIcon::ActivationReason reason); public slots: void changeConnect(bool connect); private: QSystemTrayIcon tray; QAction* changeConnectAction;};
C++ (Qt)#include "mainwindow.h"#include <QMenu> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ tray.setIcon(QIcon(":/app_icon")); tray.setToolTip("Tray!"); connect(&tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT(messageReceived(QSystemTrayIcon::ActivationReason))); QMenu * trayMenu = new QMenu(); changeConnectAction = trayMenu->addAction("Connect", this, SLOT(changeConnect(bool))); trayMenu->addSeparator(); trayMenu->addAction("About"); trayMenu->addSeparator(); trayMenu->addAction("Quit"); tray.setContextMenu(trayMenu); tray.show();} void MainWindow::messageReceived(QSystemTrayIcon::ActivationReason reason){ if (reason == QSystemTrayIcon::Trigger) { setVisible(!isVisible()); }} void MainWindow::changeConnect(bool connect) { if (connect) { changeConnectAction->setText("Connect"); /// ... } else { changeConnectAction->setText("Disconnect"); /// ... }}