Hi, here is a solution, and I think it works quite well in my application:
In the dialog's slot that connects with the activated() signal of the QSystemTrayIcon object, use the setParent() function as:
{
setParent(NULL, Qt::Window);
showNormal();
sysTrayIcon->hide();
}
}
void FtpDialog::sysTrayActivated(QSystemTrayIcon::ActivationReason reason)
{
if (reason == QSystemTrayIcon::Trigger){
setParent(NULL, Qt::Window);
showNormal();
sysTrayIcon->hide();
}
}
To copy to clipboard, switch view to plain text mode
And in the dialog's event() function:
bool FtpDialog
::event(QEvent *e
) {
if (e
->type
() == QEvent::WindowStateChange) { if (isMinimized()) {
setParent(tmp, Qt::SubWindow);
sysTrayIcon->show();
e->ignore();
qDebug()<<"event() called";
} else {
e->accept();
}
}
return QDialog::event(e
);
// return with QDialog's event() call anyway. }
bool FtpDialog::event(QEvent *e)
{
if (e->type() == QEvent::WindowStateChange) {
if (isMinimized()) {
setParent(tmp, Qt::SubWindow);
sysTrayIcon->show();
e->ignore();
qDebug()<<"event() called";
} else {
e->accept();
}
}
return QDialog::event(e); // return with QDialog's event() call anyway.
}
To copy to clipboard, switch view to plain text mode
Here, 'tmp' is an empty QWidget serving as a provisional 'parent' of the dialog, so that the dialog can be hidden from task-bar when minimized. In fact, you can just pass NULL as the first argument for the 'parent' widget, but in this case probably the re-stored window would exhibit slightly different with the original window size.
Bookmarks