class SystemTray : public QLabel {Q_OBJECTprivate: QSystemTrayIcon* m_ptrayIcon; QMenu* m_ptrayIconMenu; bool m_bIconSwitcher;protected: virtual void closeEvent(QCloseEvent*);public: SystemTray(QWidget* pwgt = 0);};
SystemTray::SystemTray(QWidget* pwgt) : QLabel("", pwgt) , m_bIconSwitcher(true){ QAction* pactQuit = new QAction("&Quit", this); connect(pactQuit, SIGNAL(triggered()), qApp, SLOT(quit())); m_ptrayIconMenu = new QMenu(this); m_ptrayIconMenu->addAction(pactQuit); m_ptrayIcon = new QSystemTrayIcon(this); m_ptrayIcon->setContextMenu(m_ptrayIconMenu); m_ptrayIcon->setToolTip(QString::fromLocal8Bit("Ёлочка")); m_ptrayIcon->setIcon(QPixmap(":/images/icon.gif")); m_ptrayIcon->show();}void SystemTray::closeEvent(QCloseEvent* pe){ if (m_ptrayIcon->isVisible()) { hide(); }}
#ifndef SYSTEMTRAY_H#define SYSTEMTRAY_H#include <QLabel>class QSystemTrayIcon;class QMenu;class SystemTray : public QLabel {Q_OBJECTprivate: QSystemTrayIcon* m_ptrayIcon; QMenu* m_ptrayIconMenu; bool m_bIconSwitcher;protected: virtual void closeEvent(QCloseEvent*);public: SystemTray(QWidget* pwgt = 0);};#endif // SYSTEMTRAY_H
#include "systemtray.h"#include <QtGui>#include <QTimer>SystemTray::SystemTray(QWidget* pwgt /*=0*/) : QLabel("", pwgt) , m_bIconSwitcher(true){ QAction* pactQuit = new QAction("&Quit", this); connect(pactQuit, SIGNAL(triggered()), qApp, SLOT(quit())); m_ptrayIconMenu = new QMenu(this); m_ptrayIconMenu->addAction(pactQuit); m_ptrayIcon = new QSystemTrayIcon(this); m_ptrayIcon->setContextMenu(m_ptrayIconMenu); m_ptrayIcon->setToolTip(QString::fromLocal8Bit("Ёлочка")); m_ptrayIcon->setIcon(QPixmap(":/images/icon.gif")); m_ptrayIcon->show(); hide();}void SystemTray::closeEvent(QCloseEvent* pe){ if (m_ptrayIcon->isVisible()) { hide(); }}
#include "systemtray.h"#include <QtGui>class Window : public QLabel {private: QPoint m_ptPosition;protected: virtual void Window::mousePressEvent(QMouseEvent* pe) { m_ptPosition = pe->pos(); } virtual void Window::mouseMoveEvent(QMouseEvent* pe) { move(pe->globalPos() - m_ptPosition); }public: Window(QWidget* pwgt = 0) : QLabel(pwgt, Qt::FramelessWindowHint | Qt::Window) { }};int main(int argc, char** argv){ QApplication app(argc, argv); SystemTray st; Window win; QMovie mov("elka7.gif"); QPixmap pix(":/images/elka7.gif"); win.setMask(pix.mask()); win.setMovie(&mov); win.resize(240,400); win.show(); mov.start(); return app.exec();}
virtual void Window::mousePressEvent(QMouseEvent* pe) { m_ptPosition = pe->pos(); } virtual void Window::mouseMoveEvent(QMouseEvent* pe) { move(pe->globalPos() - m_ptPosition); }
#include "window.h"#include <QtGui>class Window : public QLabel {private: QPoint m_ptPosition;protected: virtual void mousePressEvent(QMouseEvent* pe); virtual void mouseMoveEvent(QMouseEvent* pe);public: Window(QWidget* pwgt = 0) : QLabel(pwgt, Qt::Tool) { }};void Window::mousePressEvent(QMouseEvent *pe){ m_ptPosition = pe->pos();}void Window::mouseMoveEvent(QMouseEvent *pe){ move(pe->globalPos() - m_ptPosition);}int main(int argc, char** argv){ QApplication app(argc, argv); QApplication::setQuitOnLastWindowClosed(false); SystemTray st; Window win; QMovie mov("elka.gif"); QPixmap pix(":/images/elka.gif"); win.setMask(pix.mask()); win.setMovie(&mov); win.resize(240,400); win.show(); mov.start(); QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Calc", QSettings::NativeFormat); qDebug()<< settings.value("layout").toString(); settings.setValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", "Milkyway"); settings.setValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\Galaxy\\Sun", "OurStar"); settings.value("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\Galaxy\\Default"); // returns "Milkyway" return app.exec();}