views:

1366

answers:

3

I am trying to create an app in Qt/C++ with Qt4.5 and want the any active windows to change opacity on a mouseover event...

As i understand it, there is no explicit mouseover event in Qt.

However, I got rudimentary functioning by reimplementing QWidget's mousemoveevent() in the class that declares my mainwindow. But the mainwindow's mousemoveevent is not called whenever the mouse travels over any of the group boxes i have created in there (understandbly since QGroupbox has its own reimplementation of mousemoveevent).

So as a cheap work around, I am still using the mousemoveevent of my mainwindow but a query the global mouse position and based on the (x,y) position of the mainwindow (obtained through ->pos()) and the window size (-> size -> rHeight and rWidth), I check if the mouse is within the bounds of the area of the mainwindow and change the opacity thus.

This has had very limited success. The right border works fine, the the left changes opacity 4 pixels early. The top does not work (presumably because the mouse goes through the menubar and title bar) and the bottom changes way too early.

I thought of creating an empty container QWidget class and then place all the rest in there, but i felt that it would still not solve the big issue of the base widget not receiving the mousemoveevent if it has already been implemented in a child widget.

Please suggest any corrections/errors I have made in my method or any alternate methods to achieve this.

p.s. I doubt this matters, but I am working Qt Creator IDE, not Qt integration into VS2008 (it's the same classes anyways - different compiler though, mingw)

+2  A: 

Installing event filters for each of your child widgets might do the trick. This will allow your main window to receive child events such as the ones from you group boxes. You can find example code here.

Arnold Spence
+2  A: 

You may be interested in Event filters. QObject proves a way to intercept all events zipping around your application.

http://doc.trolltech.com/4.5/eventsandfilters.html#event-filters

Trey Stout
+1  A: 

If I understand what you are attempting to do, I would reimplement the widget's enterEvent() and leaveEvent(). The mouse enter event would trigger the fade-in and the leaveEvent would trigger the fade-out.

EDIT: After re-reading several times, I'm still not sure what you are trying to accomplish. Sorry if my suggestion doesn't help. :-)

JimDaniel
what i want is to change transparency on a mousevoer event.... but since QGroupBox has already implemented mousemoveevent() [reimp from QWidget] my main window does not get mousemoveevent called if mouse is over any of the froup boxes therein.....the enter and leave event was only my work around this .... but my clumsy way does not account for the menubar etc, on top .... if you have any other way of doing this, i am open to it ....
Aashay
You are saying you want to change transparency, but I can't tell what you want to change the transparency of - some code or an overview of the widgets you have and want to change would help. The event filters the others suggested might be the right solution, but it's not yet clear to me what you want.
JimDaniel