[Qt-interest] how to create custom signal and slot?
Sean Harmer
sean.harmer at maps-technology.com
Wed Sep 23 14:44:19 CEST 2009
On Wednesday 23 Sep 2009 13:27:37 Riccardo Roasio wrote:
> So you mean that in the rectangle class i need to create a slignal
> named mousePressEvent and connect it to a slot?
No. You need to reimplement virtual void mousePressEvent from QWidget. You
also need to declare a new signal called clicked() or whatever you wish to
call it. Then in your mousePressEvent() function do whatever checks you need
to do to make sure the mouse was actually pressed withing your rectangle (if
it only occupies a subset of the widget for example). If you are happy, emit
your signal from within mousePressEvent().
Then somewhere else in your code connect up your clicked() signal to a slot of
your choice to do whetever processing is needed.
Cheers,
Sean
More information about the Qt-interest-old
mailing list