PDA

View Full Version : Hide on Minimize



defunct
5th January 2006, 19:44
Hello,

I have a Windows application that places an icon in the System Tray (modified the old trayicon example to work under Qt4). My question is; When I minimize my application, I want to remove it from the taskbar. I couldn't figure out how to do this using the changeEvent or hideEvent (I think because it's a spontaneous event). To solve this, I ended up having to reimplement the winEvent function as such:


bool winEvent( MSG *m, long *result )
{
if ( mintotray )
{
switch ( m->message )
{
case WM_SIZE:
{
if ( m->wParam == SIZE_MINIMIZED )
{
ShowWindow(winId(), SW_HIDE);
return true;
}
}
break;
default:
break;
}
}

return QWidget::winEvent(m, result);
}

Is there a cleaner way to do this using Qt events?

Thanks in advance,
-d

elcuco
6th January 2006, 10:07
IMHO you should ovveride this function on your QWindow:



bool QWidget::winEvent ( MSG * message, long * result ) [virtual protected]

defunct
6th January 2006, 19:19
IMHO you should ovveride this function on your QWindow:



bool QWidget::winEvent ( MSG * message, long * result ) [virtual protected]

I did, I just didn't include the "ClassName::" to winEvent in the original post.

jacek
6th January 2006, 23:17
Try this (it's from an old thread on Qt Forum):
by the way i've solved, i've found an old thread here in the forum.
A good solution is

bool MonitorUI::event(QEvent * e )
{
if (e->type()==QEvent::ShowMinimized )
{
hide();
return true;
}
else
return QMainWindow::event(e);
}


thanks Angelo

defunct
7th January 2006, 11:18
Try this (it's from an old thread on Qt Forum):
That doesn't work. In Qt4, there is no ShowMinimized event. From what I can tell, by the time Qt4 gets the minimized event, the window has already been iconified. You can't stop it from happening (unless reimplementing winEvent, which I think is ugly).

Does anyone know a way to trap spontaneous events before they happen?

fanat9
9th January 2006, 03:57
Defunc: Can you show plz your modified trayicon example for Qt4 ?

jrbloch
22nd September 2006, 23:53
I just tried the code in the original post and it worked with QT v4.1.3. :)

sheeeng
13th January 2009, 05:31
Try this (it's from an old thread on Qt Forum):

Hi,

Thanks for the suggestion. But, it DO NOT work on Qt 4.4.3 now. :confused:

Anyone has ideas how can I hide to system tray when user click minimize or red 'x' on the upper right buttons?

Thanks in advance. :)

bmn
13th March 2009, 13:34
Hello,

Sorry for resurrecting this thread but I am trying to achieve the same thing than the original poster, trying to hide my application when the "Minimize" icon is clicked or the "Minimize" option of the window menu (the one at the upper left corner of the windows in Windows Xp) is selected.

I have tried all the suggested options (including some in other threads) without success, has anyone achieved this?

Thank you!

The Storm
26th March 2009, 10:46
void MyWindow::changeEvent ( QEvent *event )
{
if( event->type() == QEvent::WindowStateChange )
{
if( isMinimized() )
hide();
}
}


Good luck. :)