PDA

View Full Version : QT 4.3.3: QSystemTrayIcon, winEvent, how to add an on ON HOVER handler...



JohnSuykerbuyk
4th February 2008, 08:04
Hi,

I've been working with the QSystemTrayIcon component, this part of our
application is targeted towards windows exclusively, so I don't mind if
I do something that is not portable.

QSystemTrayIcon emits a number of button activated reason codes via its
"activated" signal, but I am trying to capture the event that signals
that the mouse is hovering over the tray icon, specifically in windows,
the WM_NCMOUSEHOVER event.

I've gone through the source of QSystemTrayIcon to see how its private
parts work, but I can't quite seem to figure out an appropriate (or the
best) way to capture WM_MESSAGE traffic in my tray applet, and if I
don't see the one message I am after, delegate it back down to the
QSystemTrayIcon object I am a decedent of. It seems that all pretext of
the QWidget is deeply nested inside of private classes that I can
dispatch to from my derived object.

Is there something I am missing? I can modify the
QSystemTrayIconSys::winEvent in qsystemtrayicon_win.cpp to do what I
want it to, but I don't want to be off in a private branch for my QT
source... I've tried all the ticks I can think of in my derived
QSystemTrayIcon class, but alas, it does not directly inherit from
QWidget and doing so, I still can't dispatch down my inheritance chain
to handle those things that I don't need to.

Thanks

John Suykerbuyk

luf
4th February 2008, 11:12
You can do an winEvent, but have a look at QWidget::enterEvent, as this tells you when the mouse enters the widget, you can do something similar with ordinary event and QEvent::MouseMove.

This makes the tricky part, as you can do a custom class with a subclass of QWidget and QSystemTrayIcon. (which I don't know if would work...)

But the easier solution is probably to reimplement ::event(QEvent *e)
Somthing linke this:



bool SystTrayIcon::event( QEvent e )
{
switch ( e->type() ) {
case QEvent::MouseMove:
/*
Do Mouse Move stuff Here
Should happen when the mouse is over your systray icon
*/
break;

case QEvent::MouseButtonPress:
/* Button Press things here */
break;
case QEvent::MouseButtonRelease:
/ * Do mouse release button stuff */
break;
case QEvent::MouseButtonDblClick:
/ * Do mouse double click stuff */
break;
default:
return QObject::event( e );
}


Have a look at how the systray implements the clicks if you want same functionality as it has for those options.