#include #include #include class WindowMover : public QObject { protected: bool eventFilter(QObject *obj, QEvent *event) { if(event->type() == QEvent::Move) { QWindow* window = (QWindow*)obj; QMoveEvent *ev = (QMoveEvent *)event; qDebug() << "eventFilter before" << window->position(); qDebug() << "eventFilter setto" << ev->oldPos() << ev->pos(); //I found that, after I setpostion with a negative x, i recieve another moveevent with x = 0, and it may comes from window_manager window->setPosition(ev->pos()); window->lower(); qDebug() << "eventFilter after" << window->position(); return true; } return false; } }; class MyWindow : public QQuickWindow { public: MyWindow(QWindow* parent = NULL) : QQuickWindow(parent) , _hold(NULL) { //set negative x, but it would'n help setGeometry(-50,30,200,200); } void setControl(QWindow* hold) { _hold = hold; } ~MyWindow(){} protected: void mousePressEvent(QMouseEvent *ev) { if(_hold) { //set negative x to _hold QMoveEvent moveEvent(QPoint(-100,100), _hold->position()); QCoreApplication::sendEvent(_hold, &moveEvent); } } void moveEvent(QMoveEvent *ev) { qDebug() << "moveEvent before" << position(); qDebug() << "moveEvent setto" << ev->oldPos() << ev->pos(); setPosition(ev->pos()); qDebug() << "moveEvent after" << position(); } private: QWindow* _hold; }; int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); WindowMover windowMover; MyWindow mywindow1; mywindow1.setTitle("mywindow1"); /** * set this flag would be help, but I can't accept the top-most window allways overlap other window */ //mywindow1.setFlags(Qt::X11BypassWindowManagerHint); mywindow1.installEventFilter(&windowMover); mywindow1.show(); MyWindow mywindow2; mywindow2.setTitle("mywindow2"); /** * I want to control the mywindow1's move, but I can't set parent because I want to paint something * on the mywindow1 and mywindow2 either, and setparent would be an overlap issue */ mywindow2.setControl(&mywindow1); mywindow2.show(); return app.exec(); }