[Qt-interest] how to create custom signal and slot?
John McClurkin
jwm at nei.nih.gov
Wed Sep 23 13:37:36 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?
>
>
> Thanks,
> Riccardo
Is the rectangle an object that inherits QObject? If so, just override
the object's mousePressEvent function and emit whatever signal you want.
If the rectangle is drawn on an object, you will have to subclass that
object and override that object's mousePressEvent function. In this
case, in the mousePressEvent function, you will have to compare the
position of the mouse with the position of the rectangle and emit a
signal if the mouse is in the rectangle.
More information about the Qt-interest-old
mailing list