Reputation: 1
I've been working on a Qt C++ application that deals with video processing. It usually takes a long time so that user would start the process and minimize the window to wait.
Now I'm encountering the problem that user cannot be alerted when the process is finished. I can show a QMessageBox within the application in the foreground. However there is no message that can actively notify the user when he minimizes the application and works on other stuff.
This notification doesn't have to be a pop-up. It could even be blinking in the taskbar. Any suggestions would be appreciated.
Thanks in advance!
EDIT:
I appreciate every one's quick and detailed response. QMessageBox and QSystemTrayIcon are two possible solutions. I do partially solve my problem by the following code:
HWND hHandle = FindWindow(NULL,L"nameOfYourApplication");
FLASHWINFO pf;
pf.cbSize = sizeof(FLASHWINFO);
pf.hwnd = hHandle;
pf.dwFlags = FLASHW_TIMER|FLASHW_TRAY; // (or FLASHW_ALL to flash and if it is not minimized)
pf.uCount = 8;
pf.dwTimeout = 75;
FlashWindowEx(&pf);
This will flash the taskbar. Once again, thanks so much for every one involved in this!
Upvotes: 0
Views: 2310
Reputation: 114
Inside QMainWindow:
ShowWindow((HWND)this->winId(), SW_MINIMIZE);//#include <windows.h>
ShowWindow((HWND)this->winId(), SW_MAXIMIZE);
showMessageBox();
Upvotes: 1
Reputation: 18504
QSystemTrayIcon
is normal solution, but you should add new code, and many apps in trays can be annoying, so you should be sure that your app really need icon tray. And back to the original question:
If you use this:
QMessageBox::information(this,"title","text");
then your QMessageBox
will be really hidden as your window, but when you use this:
qApp->setQuitOnLastWindowClosed(false);
QMessageBox box;
box.setText("text");
box.exec();
Or this for example:
qApp->setQuitOnLastWindowClosed(false);
QMessageBox *box = new QMessageBox(this);
box->setWindowTitle("title");
box->setText("text");
box->show();
Then you get this QMessageBox
if your window is hidden or not.
Why we need qApp->setQuitOnLastWindowClosed(false);
? By default, a Qt application closes when the last window is closed, so if you close this box but windows will be hidden, then app will be closed. With setQuitOnLastWindowClosed
it will run normal.
Edit:
QMessageBox *box = new QMessageBox;
box->setWindowTitle("title");
box->setText("text");
box->show();
this->showNormal();
Upvotes: 0
Reputation: 2102
You can use QSystemTrayIcon to show the messagex from the taskbar tray.
Use method QSystemTrayIcon::showMessage to fire a notification.
And with QSystemTrayIcon::setVisible(bool visible) you can show/hide the icon in the tray.
Use QSystemTrayIcon::setIcon to setup required icon.
Upvotes: 2