PDA

View Full Version : Click events



Maluko_Da_Tola
26th August 2010, 02:05
Hi,

I am trying to get a QLabel widget to handle mouse left click events. The label is in a layout, alongside other widgets. I subclassed QLabel and created a myQLabel widget, which contains the virtual methods for handling mouseEvents. However, when I run the application, the label does not handle any click events. On the myLabel header file I put


protected:
virtual void mousePressEvent(QMouseEvent *event);


On the myLabel.cpp file I wrote the following definition for the mousePressEvent:

void MyLabel::mousePressEvent(QMouseEvent *event)
{
if (event->button()==Qt::leftButton){

//code for the mouse click event
}
}

How can I make the label respond to mouse clicks and execute the code for the mouse click event?

Thank you