class Test : public QLabel{private:QPoint point;QWidget wgt;protected: virtual void mousePressEvent(QMouseEvent* pe){ if(pe->button() & Qt::LeftButton) point = pe->pos(); } virtual void mouseMoveEvent(QMouseEvent* pe){ move(pe->globalPos() - point); } virtual void keyPressEvent(QKeyEvent* pe){ if(pe->key() & Qt::Key_Enter){ slotStart(); } }public:Test(QWidget* parent = 0) : QLabel(parent){// основное окно//.....//.....wgt.show();}
C++ (Qt)virtual void mousePressEvent(QMouseEvent* pe){ QLabel::mousePressEvent( pe ); if(pe->button() & Qt::LeftButton) point = pe->pos();}
wgt.setParent(this);
class Timer : public QLabel{ Q_OBJECTprivate:QPoint point;QWidget wh;protected: virtual void Timer::mousePressEvent(QMouseEvent* pe){ if(pe->button() & Qt::LeftButton) point = pe->pos(); } virtual void Timer::mouseMoveEvent(QMouseEvent* pe){ move(pe->globalPos() - point); } virtual void Timer::keyPressEvent(QKeyEvent* pe){ if(pe->key() & Qt::Key_Enter){ slotStart(); } }public: Timer(QWidget *parent = 0);}
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(); }};