PDA

View Full Version : Hide on Minimize


defunct
5th January 2006, 18: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, 09:07
IMHO you should ovveride this function on your QWindow:


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

defunct
6th January 2006, 18: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, 22: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, 10: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, 02:57
Defunc: Can you show plz your modified trayicon example for Qt4 ?

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