Maluko_Da_Tola
26th August 2010, 23:52
Hi,
I am trying to sublass QLabel to create a label capable of handling mouse click events. The following code works fine:
#include <QtGui>
class MyLabel : public QLabel
{
Q_OBJECT
public:
protected:
virtual void mousePressEvent(QMouseEvent *event)
{
if (event->button()==Qt::LeftButton)
{
qWarning() << Q_FUNC_INFO;
}
}
};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyLabel l;
l.setText("foo bar");
l.show();
return app.exec();
}
What I don't understand is, when I try to define MyLabel class in a seperate header file, Qt does not compile anymore! Why is this happening?
Thank you
I am trying to sublass QLabel to create a label capable of handling mouse click events. The following code works fine:
#include <QtGui>
class MyLabel : public QLabel
{
Q_OBJECT
public:
protected:
virtual void mousePressEvent(QMouseEvent *event)
{
if (event->button()==Qt::LeftButton)
{
qWarning() << Q_FUNC_INFO;
}
}
};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyLabel l;
l.setText("foo bar");
l.show();
return app.exec();
}
What I don't understand is, when I try to define MyLabel class in a seperate header file, Qt does not compile anymore! Why is this happening?
Thank you