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

John McClurkin jwm at nei.nih.gov
Wed Sep 23 19:08:16 CEST 2009


Riccardo Roasio wrote:
> mmmmmmmm....
> 
> I'm a little confused....
> 
> I have a class called RenderArea that extend QWidget and a class
> called Rectangle that extend QObject.
> An object of type REctangle is created into the RenderArea object.
> Now....
> 
> i have to reimplement mousePressEvent into the Rectangle class? Or in
> the in the Rectangle class?
> For the clicked() signal i think i need to create it into the REctangle class.
> 
> Correct?
> 
> Thanks for the Expalnations,
> Riccardo
> 

As the two Seans say below, the best bet overall is to use QGraphicsView 
and QGraphicsItem, but the most direct way to proceed from where you are 
is to have your Rectangle object inherit QWidget, not QObject. Your 
Rectangle object then will receive mouse events. You then override the 
QWidget::mousePressEvent in your Rectangle object and emit signals from 
there. Also, make sure you understand Qt's signals and slots feature. 
This is not the same as events or unix signals.



More information about the Qt-interest-old mailing list