View Full Version : Windws Taskbar Entry

31st July 2007, 17:20
Hi All,

I have tried everything I can find in this forum and on the web to get this to work, and nothing seems to solve my problem.

I have a program made with QT 4.3, which should hide to the tray icon.

When I hide it using the tray icon, it works fine, even on Windows the task-bar entry goes away, leaving just the icon tray:

void vfalerter::iconClicked( QSystemTrayIcon::ActivationReason reason )

if( reason == QSystemTrayIcon::Trigger ) {
// The icon in the tray was clicked
else if( reason == QSystemTrayIcon::MiddleClick ) {
// The icon was middle-clicked
showPopup( statusText, 1 );

That part works great. But when i try and capture the Minimize event from the main window, it leaves the task bar entry there.

bool vfalerter::eventFilter(QObject *obj, QEvent *event)
if( event->type() == QEvent::Hide ) {
// Window was minimized
return false;
else if( event->type() == QEvent::Close) {
// We are exiting

// Delete any popups
while( popups.count() )
delPopup( popups[0] );
return false;
else if( event->type() == QEvent::Show) {
return false;
else {
// Other events should be passed back to the main window
return QObject::eventFilter(obj, event);

The only way I have been able to make the taskbar entry go away in Windows from the minimize button is by adding:

setWindowFlags( Qt::SubWindow );

..to the hide function, but then the window never comes back the way it was when I restore it, and I'm pretty sure that wouldn't be the right way of doing it.

The whole things works as expected in KDE, its just Windows that has a problem.

Anyone got any ideas?

31st July 2007, 21:01
When you minimize, you return false in the event filter. This is a problem since the "other" things won't be performed by the subclass for this event. By "other" I mean the stuff related to minimizing to tray and setting the appropriate flags for the window to disappear from task bar.

I suggest returning the base class version of eventFilter instead of false.


1st August 2007, 03:11
I think I already tried that, didn't seem to help.

I don't understand why the hide in the IconTray function works fine, but the one in the Event does not :-(

1st August 2007, 12:53
The event for a state change( e.g. minimize) is QWindowStateChangeEvent.

So I think that your mistake is to call hide() for a hide event. Well, a call to hide() triggered that event in the first place.

So you should handle this event instead,, and hide it there. Also you should ignore the event in this case, because you don't actually want to minimize the window. You just want to use the minimize button for hiding the window.

Please refer to the System Tray example in the Qt Demos for a full example.
Here's a small snippet:

void Window::closeEvent(QCloseEvent *event)
if (trayIcon->isVisible()) {
QMessageBox::information(this, tr("Systray"),
tr("The program will keep running in the "
"system tray. To terminate the program, "
"choose <b>Quit</b> in the context menu "
"of the system tray entry."));
This is how they implemented it. They hide the task bar button at close. The only difference is that you hide it at minimize, so the implementation should be the same.