PDA

View Full Version : Acessing a widget's mouse event that was declared localy and smoothing



Momergil
10th January 2014, 03:06
Hello!

In one of my applications, I want that some QWidgets with some labels appear in the desktop when a given signal is emitted, while this QWidgets should have the same functionality of the messages from a QSystemTrayIcon: if the user clicks on them, the widget dissapear. This all with a notice: I prefer not the create a QWidget subclass in a new .cpp and .hpp and .ui files; I'ld like to creates them inside the slot connected to the signal, if possible.

There are two questions I would like to do regarding this situation:

1º: how may I program the code in order for the tracking of the on click QMouseEvent to work, closing the QWidget? I know that, if I create a new class, I would just have to reimplement the mouseEvent(QMouseEvent*), but remember that I'ld like to do this directly by coding in the slot.
2º: in this same situation, how to add a smooth¹ event both when the widgets is appearing as well as when it dissapears after a click on it is made?


Thanks,

Momergil

¹: not sure if this is the appropriate word... By that I mean that the widget will not appear suddently on the screen, but gradually, like the messages from QSystemTrayIcon do.

stampede
10th January 2014, 07:49
For 1. you can install event filter on the newly created widget.
For 2., I don't know how to implement this without reimplementing widget's paintEvent.

anda_skoa
10th January 2014, 10:33
This all with a notice: I prefer not the create a QWidget subclass in a new .cpp and .hpp and .ui files

Can we ask why? Is this some obscure C++ contest where the purpose is to make the code as unreadable as possible?
Or a contest where the goal is to use as few files as possible?

Cheers,
_

Momergil
10th January 2014, 12:10
Hello anda_skoa,

the second option ;) Or more precisely, the problem is that my project has already up to 30 cpp/hpp/ui files, what makes it quite poluted, so I prefer to use the files for more difficult dialogs/windows while keeping small and less difficult classes to "direct code". :)

stampede,

thanks. I guess, then, I'll have to create a new class that implements QWidgets and adds both event filter and paintEvent.

wysota
10th January 2014, 12:29
If you want animations then QPropertyAnimation is your friend. You can combine it with window opacity to try to achieve the effect you want.

anda_skoa
10th January 2014, 16:20
the second option ;) Or more precisely, the problem is that my project has already up to 30 cpp/hpp/ui files, what makes it quite poluted, so I prefer to use the files for more difficult dialogs/windows while keeping small and less difficult classes to "direct code". :)


You can use subdirectories in Qt projects to organize files.

But if you prefer messing up your code, go for it :)

Cheers,
_