[Qt-interest] how to create custom signal and slot?

Andre Somers andre at familiesomers.nl
Wed Sep 23 13:25:13 CEST 2009


Riccardo Roasio wrote:
> Hi,
>
> i have an object that paint a rectangle in the screen.
> I wolud like to use signal/slot on this object to intercept if a user
> click on the drawed rectangle.
> How can i create custom mouseEvent signal and slot and connect them?
>
>   
IMHO,
The easiest way is to derive your custom object from something as close 
as possible in functionality to what you have. In your case, you want to 
respond on a click on the object, and send out a signal. Why not use a 
QPushButton as your rectangle? You can subclass it to make it look 
however you want, but still use it's already supplied signals and slots.

If you have a good reason, you can also of course simply declare your 
own custom signal in the header of your QWidget derived object, 
reïmplement the mouse event to emit the signal you defined.

André




More information about the Qt-interest-old mailing list