#include #include #include #include class TChild : public QWidget { public: TChild(QWidget* parent, QWidget* other) : QWidget(parent, Qt::Dialog), m_other(other) { } void mouseReleaseEvent(QMouseEvent*) { setParent(m_other, windowFlags()); // SetWindowLongPtr((HWND)winId(), GWL_HWNDPARENT, m_other ? (LONG_PTR)m_other->winId() : 0); show(); } QWidget* m_other; }; int main(int argc, char** argv) { QApplication app(argc, argv); QWidget* window = new QWidget(0, Qt::Window); window->setWindowTitle("Parent 1"); window->resize(400,400); window->move(100,100); window->show(); QWidget* window2 = new QWidget(0, Qt::Window); window2->setWindowTitle("Parent 2"); window2->resize(400,400); window2->move(200,200); window2->show(); TChild* window3 = new TChild(window2, window); window3->setWindowTitle("Child"); window3->resize(200,200); window3->move(300,300); window3->show(); return app.exec(); }