http://browniz1004.blog.me/220956638885
qt 트레이 showMinimized() tray -> 나의 검색어
[헤더파일]
QSystemTrayIcon *TrayIcon; //전역변수
QMenu *TrayIconMenu;
private slots:
void onSystemTryIconClicked(QSystemTrayIcon::ActivationReason); //트레이아이콘 클릭시 이벤트 설정
void on_actionExit_triggered(); //트레이아이콘 메뉴설정시 사용
private: //프로그램종료시, 프로그램 숨김시 이벤트설정
void closeEvent(QCloseEvent *event);
void hideEvent(QHideEvent *event);
[소스파일]
TrayIcon = new QSystemTrayIcon(this);
TrayIconMenu = new QMenu(this);
TrayIconMenu->addAction(ui.actionExit);
TrayIconMenu->addSeparator();
TrayIcon->setContextMenu(TrayIconMenu);
QIcon Icon(":/appMain/Resources/icon_menu_01.png"); //아이콘은 기존 리소스 경로로 지정
TrayIcon->setIcon(Icon);
TrayIcon->show();
TrayIcon->setToolTip(tr("DFC")); //트레이아이콘에 마우스 움직였을때 문구
TrayIcon->showMessage(tr("DFC"), tr("DFC."), QSystemTrayIcon::Information, 5000); //트레이아이콘 처음 적용시 설명
connect(TrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(onSystemTryIconClicked(QSystemTrayIcon::ActivationReason)));
함수 선언부
void appMain::onSystemTryIconClicked(QSystemTrayIcon::ActivationReason reason)
{
switch (reason)
{
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
this->setWindowState(Qt::WindowActive);
this->show();
break;
}
}
void appMain::hideEvent(QHideEvent *event)
{
if (isMinimized())
{
this->hide();
}
QWidget::hideEvent(event);
}
void appMain::closeEvent(QCloseEvent *event)
{
if (TrayIcon->isVisible())
{
TrayIcon->hide();
}
}
void appMain::on_actionExit_triggered()
{
this->hide();
this->close();
}
댓글 달기