PDA

View Full Version : MSG not defined (winEvent)



December
19th February 2007, 11:21
Hi All,

I am trying to make my program hide (leaving only the icon tray) when a user clicks the minimize. I first tried the resizeEvent, but it seems this doesn't get called when the window is Minimized.

Searching the forum found mentions of winEvent and tried that in my header file:



protected:
bool winEvent( MSG * );


.. but when I try and compile, I always get



error: ‘MSG’ has not been declared


I can't find it in any headers.. what do I need to include to get that to work?

Thanks in advance.

jpn
19th February 2007, 12:05
You can override QWidget::changeEvent() and catch QEvent::WindowStateChange. The event will be sent whenever the window's state (minimized, maximized or full-screen) has changed.

jpn
19th February 2007, 14:38
I just realized you are using Qt3. The event type (QEvent::WindowStateChange) is the same for Qt3, but there is no changeEvent() so override QWidget::event() instead.

December
19th February 2007, 15:58
Hi Jpn,

I tied that.. but now just about everything has stopped working.. I tried returning both true and false, but still the main UI doesn't seem to draw, the close buttons etc don't work.

jpn
19th February 2007, 16:04
I tied that.. but now just about everything has stopped working.. I tried returning both true and false, but still the main UI doesn't seem to draw, the close buttons etc don't work.
The event must be passed to the base class implementation so that the event gets further delivered to the correct specialized event handler. For example:


bool MyWidget::event(QEvent* e)
{
if (e->type() == QEvent::WindowStateChange)
{
// minimized, maximized or fullscreen state changed, do something..
}
return QWidget::event(e); // <-- important
}

December
19th February 2007, 16:19
That was it.. thanks loads :)

I had just about figure out that I could do it using an Event filter.. which is the better approach?

jpn
19th February 2007, 16:24
I had just about figure out that I could do it using an Event filter.. which is the better approach?
Sure, both ways work. It's just a matter of taste. Overriding an event handler in most cases results into a cleaner solution than installing an event filter. Installing an event filter might save you from subclassing but the functionality ends up into a "wrong" class..