11

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.


sources :

https://stackoverflow.com/questions/4349769/getting-mouse-click-location-of-a-label-in-qt

https://stackoverflow.com/questions/38235525/how-to-add-a-custom-widget-to-qt-4-8-6

'QT' 카테고리의 다른 글

QML OPENCV 연동 예제  (0) 2019.09.03
QT invokeMethod 예제  (0) 2019.03.22
qt msvc-version.conf 설정  (0) 2019.03.18
커스텀 위젯 만들기 노트  (0) 2019.03.17
Qt 동적 라이브러리 만들기 및 사용하기  (0) 2019.03.16

+ Recent posts