C++ (Qt)class A{public: A() {} protected: void mousePressEvent(QMouseEvent* pe) { qDebug() << Q_FUNC_INFO << "\n"; if (pe->button() & Qt::LeftButton) point = pe->pos(); } void mouseMoveEvent(QMouseEvent* pe) { qDebug() << Q_FUNC_INFO << "\n"; QWidget *w = self(); w->move(pe->globalPos() - point); } void keyPressEvent(QKeyEvent* pe) { if(pe->key() & Qt::Key_Enter) { start(); } } void start() { qDebug() << Q_FUNC_INFO << "\n"; } QWidget *self() { return 0; } private: QPoint point;}; class Widget : public QWidget, public A{ Q_OBJECTpublic: Widget(QWidget *parent = 0) : QWidget(parent), A() { } protected: void mousePressEvent(QMouseEvent* pe) { qDebug() << Q_FUNC_INFO; A::mousePressEvent(pe); } void mouseMoveEvent(QMouseEvent* pe) { qDebug() << Q_FUNC_INFO; A::mouseMoveEvent(pe); } void keyPressEvent(QKeyEvent* pe) { qDebug() << Q_FUNC_INFO; A::keyPressEvent(pe); } QWidget *self() { return this; } private slots: void slotStart() { start(); }}; class Timer : public QLabel, public A{ Q_OBJECTprivate: Widget *wh; private slots: void slotStart() { start(); } protected: void mousePressEvent(QMouseEvent* pe) { qDebug() << Q_FUNC_INFO; A::mousePressEvent(pe); } void mouseMoveEvent(QMouseEvent* pe) { qDebug() << Q_FUNC_INFO; A::mouseMoveEvent(pe); } void keyPressEvent(QKeyEvent* pe) { qDebug() << Q_FUNC_INFO; A::keyPressEvent(pe); } QWidget *self() { return this; } public: Timer(QWidget *parent = 0) : QLabel("label", parent), A), wh(new Widget) { wh->show(); }};
void keyPressEvent(QKeyEvent* pe){ if(pe->key() & Qt::Key_Enter){ slotStart(); } }
C++ (Qt)void Timer::mousePressEvent(QMouseEvent* pe) { qDebug() << Q_FUNC_INFO; wh->mousePressEvent(pe); }