I googled around and found this forum thread in which the OP seems to have had the exact problem I am having. The question is, how would I inherit from QLabel
a
Yes, you can set up a signal on your CustomLabel
class and have your overridden version of mousePressEvent
emit it. i.e.
class CustomLabel : public QLabel
{
Q_OBJECT
signals:
void mousePressed( const QPoint& );
public:
CustomLabel( QWidget* parent = 0, Qt::WindowFlags f = 0 );
CustomLabel( const QString& text, QWidget* parent = 0, Qt::WindowFlags f = 0 );
void mousePressEvent( QMouseEvent* ev );
};
void CustomLabel::mousePressEvent( QMouseEvent* ev )
{
const QPoint p = ev->pos();
emit mousePressed( p );
}
CustomLabel::CustomLabel( QWidget * parent, Qt::WindowFlags f )
: QLabel( parent, f ) {}
CustomLabel::CustomLabel( const QString& text, QWidget* parent, Qt::WindowFlags f )
: QLabel( text, parent, f ) {}
The constructors just mimic those of the base QLabel
and therefore simply pass their arguments straight on to the corresponding base constructors.