Yes, that can be done by an event filter, as zlatko already said.
You should catch move events though, not mouse move events..
mywidget.h:
public:
...
....
}
class MyWidget : public QWidget {
public:
...
bool eventFilter(QObject* o, QEvent* e);
....
}
To copy to clipboard, switch view to plain text mode
mywidget.cpp:
if (e
->type
() == QEvent::Move) { QMoveEvent* moveEvent
= static_cast<QMoveEvent
*>
(e
);
// move this widget here
// (moveEvent->pos() contains the position of main window)
}
return FALSE;
}
bool MyWidget::eventFilter(QObject* o, QEvent* e) {
if (e->type() == QEvent::Move) {
QMoveEvent* moveEvent = static_cast<QMoveEvent*>(e);
// move this widget here
// (moveEvent->pos() contains the position of main window)
}
return FALSE;
}
To copy to clipboard, switch view to plain text mode
myMainForm w;
...
MyWidget mw2;
...
w.installEventFilter(&mw2);
myMainForm w;
...
MyWidget mw2;
...
w.installEventFilter(&mw2);
To copy to clipboard, switch view to plain text mode
So the widget filters all events going to the main form.
Whenever the main form is moved, the widget notices the move event and follows..
Bookmarks