A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQSystemTrayIcon</id>
		<title>C++/Qt/QSystemTrayIcon - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQSystemTrayIcon"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QSystemTrayIcon&amp;action=history"/>
		<updated>2026-04-18T17:03:47Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QSystemTrayIcon&amp;diff=1012&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QSystemTrayIcon&amp;diff=1012&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QSystemTrayIcon&amp;diff=1013&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QSystemTrayIcon&amp;diff=1013&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:32Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==System tray icon==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the examples of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef WINDOW_H&lt;br /&gt;
#define WINDOW_H&lt;br /&gt;
#include &amp;lt;QSystemTrayIcon&amp;gt;&lt;br /&gt;
#include &amp;lt;QDialog&amp;gt;&lt;br /&gt;
QT_BEGIN_NAMESPACE&lt;br /&gt;
class QAction;&lt;br /&gt;
class QCheckBox;&lt;br /&gt;
class QComboBox;&lt;br /&gt;
class QGroupBox;&lt;br /&gt;
class QLabel;&lt;br /&gt;
class QLineEdit;&lt;br /&gt;
class QMenu;&lt;br /&gt;
class QPushButton;&lt;br /&gt;
class QSpinBox;&lt;br /&gt;
class QTextEdit;&lt;br /&gt;
QT_END_NAMESPACE&lt;br /&gt;
&lt;br /&gt;
class Window : public QDialog&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    Window();&lt;br /&gt;
    void setVisible(bool visible);&lt;br /&gt;
protected:&lt;br /&gt;
    void closeEvent(QCloseEvent *event);&lt;br /&gt;
private slots:&lt;br /&gt;
    void setIcon(int index);&lt;br /&gt;
    void iconActivated(QSystemTrayIcon::ActivationReason reason);&lt;br /&gt;
    void showMessage();&lt;br /&gt;
    void messageClicked();&lt;br /&gt;
private:&lt;br /&gt;
    void createIconGroupBox();&lt;br /&gt;
    void createMessageGroupBox();&lt;br /&gt;
    void createActions();&lt;br /&gt;
    void createTrayIcon();&lt;br /&gt;
    QGroupBox *iconGroupBox;&lt;br /&gt;
    QLabel *iconLabel;&lt;br /&gt;
    QComboBox *iconComboBox;&lt;br /&gt;
    QCheckBox *showIconCheckBox;&lt;br /&gt;
    QGroupBox *messageGroupBox;&lt;br /&gt;
    QLabel *typeLabel;&lt;br /&gt;
    QLabel *durationLabel;&lt;br /&gt;
    QLabel *durationWarningLabel;&lt;br /&gt;
    QLabel *titleLabel;&lt;br /&gt;
    QLabel *bodyLabel;&lt;br /&gt;
    QComboBox *typeComboBox;&lt;br /&gt;
    QSpinBox *durationSpinBox;&lt;br /&gt;
    QLineEdit *titleEdit;&lt;br /&gt;
    QTextEdit *bodyEdit;&lt;br /&gt;
    QPushButton *showMessageButton;&lt;br /&gt;
    QAction *minimizeAction;&lt;br /&gt;
    QAction *maximizeAction;&lt;br /&gt;
    QAction *restoreAction;&lt;br /&gt;
    QAction *quitAction;&lt;br /&gt;
    QSystemTrayIcon *trayIcon;&lt;br /&gt;
    QMenu *trayIconMenu;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;window.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Window::Window()&lt;br /&gt;
{&lt;br /&gt;
    createIconGroupBox();&lt;br /&gt;
    createMessageGroupBox();&lt;br /&gt;
    iconLabel-&amp;gt;setMinimumWidth(durationLabel-&amp;gt;sizeHint().width());&lt;br /&gt;
    createActions();&lt;br /&gt;
    createTrayIcon();&lt;br /&gt;
    connect(showMessageButton, SIGNAL(clicked()), this, SLOT(showMessage()));&lt;br /&gt;
    connect(showIconCheckBox, SIGNAL(toggled(bool)),&lt;br /&gt;
            trayIcon, SLOT(setVisible(bool)));&lt;br /&gt;
    connect(iconComboBox, SIGNAL(currentIndexChanged(int)),&lt;br /&gt;
            this, SLOT(setIcon(int)));&lt;br /&gt;
    connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));&lt;br /&gt;
    connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),&lt;br /&gt;
            this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));&lt;br /&gt;
    QVBoxLayout *mainLayout = new QVBoxLayout;&lt;br /&gt;
    mainLayout-&amp;gt;addWidget(iconGroupBox);&lt;br /&gt;
    mainLayout-&amp;gt;addWidget(messageGroupBox);&lt;br /&gt;
    setLayout(mainLayout);&lt;br /&gt;
    iconComboBox-&amp;gt;setCurrentIndex(1);&lt;br /&gt;
    trayIcon-&amp;gt;show();&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;Systray&amp;quot;));&lt;br /&gt;
    resize(400, 300);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Window::setVisible(bool visible)&lt;br /&gt;
{&lt;br /&gt;
    minimizeAction-&amp;gt;setEnabled(visible);&lt;br /&gt;
    maximizeAction-&amp;gt;setEnabled(!isMaximized());&lt;br /&gt;
    restoreAction-&amp;gt;setEnabled(isMaximized() || !visible);&lt;br /&gt;
    QDialog::setVisible(visible);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Window::closeEvent(QCloseEvent *event)&lt;br /&gt;
{&lt;br /&gt;
    if (trayIcon-&amp;gt;isVisible()) {&lt;br /&gt;
        QMessageBox::information(this, tr(&amp;quot;Systray&amp;quot;),&lt;br /&gt;
                                 tr(&amp;quot;The program will keep running in the &amp;quot;&lt;br /&gt;
                                    &amp;quot;system tray. To terminate the program, &amp;quot;&lt;br /&gt;
                                    &amp;quot;choose &amp;lt;b&amp;gt;Quit&amp;lt;/b&amp;gt; in the context menu &amp;quot;&lt;br /&gt;
                                    &amp;quot;of the system tray entry.&amp;quot;));&lt;br /&gt;
        hide();&lt;br /&gt;
        event-&amp;gt;ignore();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Window::setIcon(int index)&lt;br /&gt;
{&lt;br /&gt;
    QIcon icon = iconComboBox-&amp;gt;itemIcon(index);&lt;br /&gt;
    trayIcon-&amp;gt;setIcon(icon);&lt;br /&gt;
    setWindowIcon(icon);&lt;br /&gt;
    trayIcon-&amp;gt;setToolTip(iconComboBox-&amp;gt;itemText(index));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Window::iconActivated(QSystemTrayIcon::ActivationReason reason)&lt;br /&gt;
{&lt;br /&gt;
    switch (reason) {&lt;br /&gt;
    case QSystemTrayIcon::Trigger:&lt;br /&gt;
    case QSystemTrayIcon::DoubleClick:&lt;br /&gt;
        iconComboBox-&amp;gt;setCurrentIndex((iconComboBox-&amp;gt;currentIndex() + 1)&lt;br /&gt;
                                      % iconComboBox-&amp;gt;count());&lt;br /&gt;
        break;&lt;br /&gt;
    case QSystemTrayIcon::MiddleClick:&lt;br /&gt;
        showMessage();&lt;br /&gt;
        break;&lt;br /&gt;
    default:&lt;br /&gt;
        ;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Window::showMessage()&lt;br /&gt;
{&lt;br /&gt;
    QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(&lt;br /&gt;
            typeComboBox-&amp;gt;itemData(typeComboBox-&amp;gt;currentIndex()).toInt());&lt;br /&gt;
    trayIcon-&amp;gt;showMessage(titleEdit-&amp;gt;text(), bodyEdit-&amp;gt;toPlainText(), icon,&lt;br /&gt;
                          durationSpinBox-&amp;gt;value() * 1000);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Window::messageClicked()&lt;br /&gt;
{&lt;br /&gt;
    QMessageBox::information(0, tr(&amp;quot;Systray&amp;quot;),&lt;br /&gt;
                             tr(&amp;quot;Sorry, I already gave what help I could.\n&amp;quot;&lt;br /&gt;
                                &amp;quot;Maybe you should try asking a human?&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Window::createIconGroupBox()&lt;br /&gt;
{&lt;br /&gt;
    iconGroupBox = new QGroupBox(tr(&amp;quot;Tray Icon&amp;quot;));&lt;br /&gt;
    iconLabel = new QLabel(&amp;quot;Icon:&amp;quot;);&lt;br /&gt;
    iconComboBox = new QComboBox;&lt;br /&gt;
    iconComboBox-&amp;gt;addItem(QIcon(&amp;quot;:/images/bad.svg&amp;quot;), tr(&amp;quot;Bad&amp;quot;));&lt;br /&gt;
    iconComboBox-&amp;gt;addItem(QIcon(&amp;quot;:/images/heart.svg&amp;quot;), tr(&amp;quot;Heart&amp;quot;));&lt;br /&gt;
    iconComboBox-&amp;gt;addItem(QIcon(&amp;quot;:/images/trash.svg&amp;quot;), tr(&amp;quot;Trash&amp;quot;));&lt;br /&gt;
    showIconCheckBox = new QCheckBox(tr(&amp;quot;Show icon&amp;quot;));&lt;br /&gt;
    showIconCheckBox-&amp;gt;setChecked(true);&lt;br /&gt;
    QHBoxLayout *iconLayout = new QHBoxLayout;&lt;br /&gt;
    iconLayout-&amp;gt;addWidget(iconLabel);&lt;br /&gt;
    iconLayout-&amp;gt;addWidget(iconComboBox);&lt;br /&gt;
    iconLayout-&amp;gt;addStretch();&lt;br /&gt;
    iconLayout-&amp;gt;addWidget(showIconCheckBox);&lt;br /&gt;
    iconGroupBox-&amp;gt;setLayout(iconLayout);&lt;br /&gt;
}&lt;br /&gt;
void Window::createMessageGroupBox()&lt;br /&gt;
{&lt;br /&gt;
    messageGroupBox = new QGroupBox(tr(&amp;quot;Balloon Message&amp;quot;));&lt;br /&gt;
    typeLabel = new QLabel(tr(&amp;quot;Type:&amp;quot;));&lt;br /&gt;
    typeComboBox = new QComboBox;&lt;br /&gt;
    typeComboBox-&amp;gt;addItem(tr(&amp;quot;None&amp;quot;), QSystemTrayIcon::NoIcon);&lt;br /&gt;
    typeComboBox-&amp;gt;addItem(style()-&amp;gt;standardIcon(&lt;br /&gt;
            QStyle::SP_MessageBoxInformation), tr(&amp;quot;Information&amp;quot;),&lt;br /&gt;
            QSystemTrayIcon::Information);&lt;br /&gt;
    typeComboBox-&amp;gt;addItem(style()-&amp;gt;standardIcon(&lt;br /&gt;
            QStyle::SP_MessageBoxWarning), tr(&amp;quot;Warning&amp;quot;),&lt;br /&gt;
            QSystemTrayIcon::Warning);&lt;br /&gt;
    typeComboBox-&amp;gt;addItem(style()-&amp;gt;standardIcon(&lt;br /&gt;
            QStyle::SP_MessageBoxCritical), tr(&amp;quot;Critical&amp;quot;),&lt;br /&gt;
            QSystemTrayIcon::Critical);&lt;br /&gt;
    typeComboBox-&amp;gt;setCurrentIndex(1);&lt;br /&gt;
    durationLabel = new QLabel(tr(&amp;quot;Duration:&amp;quot;));&lt;br /&gt;
    durationSpinBox = new QSpinBox;&lt;br /&gt;
    durationSpinBox-&amp;gt;setRange(5, 60);&lt;br /&gt;
    durationSpinBox-&amp;gt;setSuffix(&amp;quot; s&amp;quot;);&lt;br /&gt;
    durationSpinBox-&amp;gt;setValue(15);&lt;br /&gt;
    durationWarningLabel = new QLabel(tr(&amp;quot;(some systems might ignore this &amp;quot;&lt;br /&gt;
                                         &amp;quot;hint)&amp;quot;));&lt;br /&gt;
    durationWarningLabel-&amp;gt;setIndent(10);&lt;br /&gt;
    titleLabel = new QLabel(tr(&amp;quot;Title:&amp;quot;));&lt;br /&gt;
    titleEdit = new QLineEdit(tr(&amp;quot;Cannot connect to network&amp;quot;));&lt;br /&gt;
    bodyLabel = new QLabel(tr(&amp;quot;Body:&amp;quot;));&lt;br /&gt;
    bodyEdit = new QTextEdit;&lt;br /&gt;
    bodyEdit-&amp;gt;setPlainText(tr(&amp;quot;Don&amp;quot;t believe me. Honestly, I don&amp;quot;t have a &amp;quot;&lt;br /&gt;
                              &amp;quot;clue.\nClick this balloon for details.&amp;quot;));&lt;br /&gt;
    showMessageButton = new QPushButton(tr(&amp;quot;Show Message&amp;quot;));&lt;br /&gt;
    showMessageButton-&amp;gt;setDefault(true);&lt;br /&gt;
    QGridLayout *messageLayout = new QGridLayout;&lt;br /&gt;
    messageLayout-&amp;gt;addWidget(typeLabel, 0, 0);&lt;br /&gt;
    messageLayout-&amp;gt;addWidget(typeComboBox, 0, 1, 1, 2);&lt;br /&gt;
    messageLayout-&amp;gt;addWidget(durationLabel, 1, 0);&lt;br /&gt;
    messageLayout-&amp;gt;addWidget(durationSpinBox, 1, 1);&lt;br /&gt;
    messageLayout-&amp;gt;addWidget(durationWarningLabel, 1, 2, 1, 3);&lt;br /&gt;
    messageLayout-&amp;gt;addWidget(titleLabel, 2, 0);&lt;br /&gt;
    messageLayout-&amp;gt;addWidget(titleEdit, 2, 1, 1, 4);&lt;br /&gt;
    messageLayout-&amp;gt;addWidget(bodyLabel, 3, 0);&lt;br /&gt;
    messageLayout-&amp;gt;addWidget(bodyEdit, 3, 1, 2, 4);&lt;br /&gt;
    messageLayout-&amp;gt;addWidget(showMessageButton, 5, 4);&lt;br /&gt;
    messageLayout-&amp;gt;setColumnStretch(3, 1);&lt;br /&gt;
    messageLayout-&amp;gt;setRowStretch(4, 1);&lt;br /&gt;
    messageGroupBox-&amp;gt;setLayout(messageLayout);&lt;br /&gt;
}&lt;br /&gt;
void Window::createActions()&lt;br /&gt;
{&lt;br /&gt;
    minimizeAction = new QAction(tr(&amp;quot;Mi&amp;amp;nimize&amp;quot;), this);&lt;br /&gt;
    connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));&lt;br /&gt;
    maximizeAction = new QAction(tr(&amp;quot;Ma&amp;amp;ximize&amp;quot;), this);&lt;br /&gt;
    connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));&lt;br /&gt;
    restoreAction = new QAction(tr(&amp;quot;&amp;amp;Restore&amp;quot;), this);&lt;br /&gt;
    connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));&lt;br /&gt;
    quitAction = new QAction(tr(&amp;quot;&amp;amp;Quit&amp;quot;), this);&lt;br /&gt;
    connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));&lt;br /&gt;
}&lt;br /&gt;
void Window::createTrayIcon()&lt;br /&gt;
{&lt;br /&gt;
    trayIconMenu = new QMenu(this);&lt;br /&gt;
    trayIconMenu-&amp;gt;addAction(minimizeAction);&lt;br /&gt;
    trayIconMenu-&amp;gt;addAction(maximizeAction);&lt;br /&gt;
    trayIconMenu-&amp;gt;addAction(restoreAction);&lt;br /&gt;
    trayIconMenu-&amp;gt;addSeparator();&lt;br /&gt;
    trayIconMenu-&amp;gt;addAction(quitAction);&lt;br /&gt;
    trayIcon = new QSystemTrayIcon(this);&lt;br /&gt;
    trayIcon-&amp;gt;setContextMenu(trayIconMenu);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;window.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    Q_INIT_RESOURCE(systray);&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    if (!QSystemTrayIcon::isSystemTrayAvailable()) {&lt;br /&gt;
        QMessageBox::critical(0, QObject::tr(&amp;quot;Systray&amp;quot;),&lt;br /&gt;
                              QObject::tr(&amp;quot;I couldn&amp;quot;t detect any system tray &amp;quot;&lt;br /&gt;
                                          &amp;quot;on this system.&amp;quot;));&lt;br /&gt;
        return 1;&lt;br /&gt;
    }&lt;br /&gt;
    QApplication::setQuitOnLastWindowClosed(false);&lt;br /&gt;
    Window window;&lt;br /&gt;
    window.show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>