Index: /trunk/src/gui/kernel/qwidget_p.h
===================================================================
--- /trunk/src/gui/kernel/qwidget_p.h	(revision 127)
+++ /trunk/src/gui/kernel/qwidget_p.h	(revision 128)
@@ -372,5 +372,5 @@
 #endif
 
-#if defined (Q_WS_WIN)
+#if defined(Q_WS_WIN) || defined(Q_WS_PM)
     void reparentChildren();
 #endif
Index: /trunk/src/gui/kernel/qwidget_pm.cpp
===================================================================
--- /trunk/src/gui/kernel/qwidget_pm.cpp	(revision 127)
+++ /trunk/src/gui/kernel/qwidget_pm.cpp	(revision 128)
@@ -1254,7 +1254,105 @@
 }
 
+void QWidgetPrivate::reparentChildren()
+{
+    Q_Q(QWidget);
+    QObjectList chlist = q->children();
+    for (int i = 0; i < chlist.size(); ++i) { // reparent children
+        QObject *obj = chlist.at(i);
+        if (obj->isWidgetType()) {
+            QWidget *w = (QWidget *)obj;
+            if ((w->windowType() == Qt::Popup)) {
+                ;
+            } else if (w->isWindow()) {
+                bool showIt = w->isVisible();
+                QPoint old_pos = w->pos();
+                w->setParent(q, w->windowFlags());
+                w->move(old_pos);
+                if (showIt)
+                    w->show();
+            } else {
+                w->d_func()->invalidateBuffer(w->rect());
+                WinSetParent(w->effectiveWinId(), q->effectiveWinId(), FALSE);
+                WinSetOwner(w->effectiveWinId(), q->effectiveWinId());
+                w->d_func()->reparentChildren();
+#if 0 // @todo check if this is really necessary any longer
+                // bring PM coords into accordance with Qt coords,
+                // otherwise setGeometry() below will wrongly position
+                // children if this widget manages their layout.
+                SWP swp;
+                int hd = q->height() - old_height;
+                WinQueryWindowPos(w->effectiveWinId(), &swp);
+                swp.y += hd;
+                WinSetWindowPos(w->effectiveWinId(), 0, swp.x, swp.y, 0, 0, SWP_MOVE);
+#endif
+            }
+        }
+    }
+}
+
 void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
 {
-    // @todo implement
+    Q_Q(QWidget);
+    bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
+    if (q->isVisible() && q->parentWidget() && parent != q->parentWidget())
+        q->parentWidget()->d_func()->invalidateBuffer(q->geometry());
+
+    WId old_fid = frameWinId();
+
+    // hide and reparent our own window away. Otherwise we might get
+    // destroyed when emitting the child remove event below. See QWorkspace.
+    if (q->isVisible() && old_fid != NULLHANDLE) {
+        qt_WinSetWindowPos(old_fid, 0, 0, 0, 0, 0, SWP_HIDE);
+        WinSetParent(old_fid, HWND_OBJECT, FALSE);
+        WinSetOwner(old_fid, NULLHANDLE);
+    }
+    bool dropSiteWasRegistered = false;
+    if (q->testAttribute(Qt::WA_DropSiteRegistered)) {
+        dropSiteWasRegistered = true;
+        q->setAttribute(Qt::WA_DropSiteRegistered, false); // ole dnd unregister (we will register again below)
+    }
+
+    if ((q->windowType() == Qt::Desktop))
+        old_fid = NULLHANDLE;
+    setWinId(0);
+
+    QObjectPrivate::setParent_helper(parent);
+    bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
+
+    data.window_flags = f;
+    data.fstrut_dirty = true;
+    q->setAttribute(Qt::WA_WState_Created, false);
+    q->setAttribute(Qt::WA_WState_Visible, false);
+    q->setAttribute(Qt::WA_WState_Hidden, false);
+    adjustFlags(data.window_flags, q);
+    // keep compatibility with previous versions, we need to preserve the created state
+    // (but we recreate the winId for the widget being reparented, again for compatibility)
+    if (wasCreated || (!q->isWindow() && parent->testAttribute(Qt::WA_WState_Created)))
+        createWinId();
+    if (q->isWindow() || (!parent || parent->isVisible()) || explicitlyHidden)
+        q->setAttribute(Qt::WA_WState_Hidden);
+    q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
+
+    if (wasCreated) {
+        reparentChildren();
+    }
+
+    if (extra && !extra->mask.isEmpty()) {
+        QRegion r = extra->mask;
+        extra->mask = QRegion();
+        q->setMask(r);
+    }
+    if (extra && extra->topextra && !extra->topextra->caption.isEmpty()) {
+        setWindowIcon_sys(true);
+        setWindowTitle_helper(extra->topextra->caption);
+    }
+    if (old_fid != NULLHANDLE)
+        qt_WinDestroyWindow(old_fid);
+
+    if (q->testAttribute(Qt::WA_AcceptDrops) || dropSiteWasRegistered
+        || (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_DropSiteRegistered)))
+        q->setAttribute(Qt::WA_DropSiteRegistered, true);
+
+    invalidateBuffer(q->rect());
 }
 
