Qt4.8.2トレイメッセージのポップアップ


#include "widget.h"

#include <QSystemTrayIcon>
#include <QMessageBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QLineEdit>
#include <qlabel>
#include <QSpinBox>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    comboTime=new QSpinBox;
    editMsg=new QLineEdit;
    editClickMsg=new QLineEdit;
    btnShow=new QPushButton(tr(" "));

    trayIcon=new QSystemTrayIcon(this);
    trayIcon->setVisible(true);

    QGridLayout *gridLayout=new QGridLayout;
    gridLayout->addWidget(new QLabel(tr(" ")),0,0);
    gridLayout->addWidget(comboTime,0,1);
    gridLayout->addWidget(new QLabel(tr(" ")),1,0);
    gridLayout->addWidget(editMsg,1,1);
    gridLayout->addWidget(new QLabel(tr(" ")),2,0);
    gridLayout->addWidget(editClickMsg,2,1);
    gridLayout->addWidget(btnShow,3,1);
    setLayout(gridLayout);

    comboTime->setSuffix(tr(" "));// 
    comboTime->setRange(5,15);
    comboTime->setValue(10);

    connect(btnShow,SIGNAL(clicked()),this,SLOT(showMsg()));
    connect(trayIcon,SIGNAL(messageClicked()),this,SLOT(showClickMsg()));
}

Widget::~Widget()
{
    
}

void Widget::showMsg()
{
    trayIcon->showMessage(tr(" "),editMsg->text(),QSystemTrayIcon::Information,comboTime->value()*1000);
}

void Widget::showClickMsg()
{
    QMessageBox::information(this,tr(" "),editClickMsg->text());
}