diff --git a/examples/widgets/mainwindows/mdi/mdi.pro b/examples/widgets/mainwindows/mdi/mdi.pro
index f2c236f7e2..212122127e 100644
--- a/examples/widgets/mainwindows/mdi/mdi.pro
+++ b/examples/widgets/mainwindows/mdi/mdi.pro
@@ -1,6 +1,6 @@
 QT += widgets
 requires(qtConfig(filedialog))
-
+CONFIG += console
 HEADERS       = mainwindow.h \
                 mdichild.h
 SOURCES       = main.cpp \
diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp
index 8a3ae17b1d..bd8b51bdef 100644
--- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp
+++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp
@@ -2176,6 +2176,7 @@ QRect QWindowsVistaStyle::subControlRect(ComplexControl control, const QStyleOpt
             if (!buttonVisible(subControl, tb))
                 return rect;
             const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget);
+            qDebug() << __FUNCTION__ << CC_TitleBar << "with nativeMetricScaleFactor=" << factor;
             const bool isToolTitle = false;
             const int height = tb->rect.height();
             const int width = tb->rect.width();
@@ -2233,6 +2234,7 @@ QRect QWindowsVistaStyle::subControlRect(ComplexControl control, const QStyleOpt
             default:
                 break;
             }
+            qDebug() << __FUNCTION__ << CC_TitleBar << "rets" << rect;
         }
         break;
     default:
diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp
index 90026e5bf0..4ec25f00fd 100644
--- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp
+++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp
@@ -744,6 +744,10 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa
     const QPointF redirectionDelta(deviceTransform.dx(), deviceTransform.dy());
     const QRect area = scaleRect(QRectF(themeData.rect), additionalDevicePixelRatio).translated(redirectionDelta).toRect();
 
+    if (themeData.partId ==  WP_MDICLOSEBUTTON || themeData.partId ==  WP_CLOSEBUTTON)
+        qDebug() <<  __FUNCTION__ << "additionalDevicePixelRatio=" << additionalDevicePixelRatio
+                  << area << "part=" << themeData.partId;
+
     QRegion sysRgn = painter->paintEngine()->systemClip();
     if (sysRgn.isEmpty())
         sysRgn = area;
@@ -761,6 +765,9 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa
 #endif
 
     RECT drawRECT = themeData.toRECT(area);
+    if (themeData.partId ==  WP_MDICLOSEBUTTON || themeData.partId ==  WP_CLOSEBUTTON)
+        qDebug() <<  __FUNCTION__ << "drawrect=" << (drawRECT.right - drawRECT.left)
+                  << 'x' << (drawRECT.bottom - drawRECT.top)<< "part=" << themeData.partId;
     DTBGOPTS drawOptions;
     memset(&drawOptions, 0, sizeof(drawOptions));
     drawOptions.dwSize = sizeof(drawOptions);
@@ -789,7 +796,9 @@ bool QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa
 {
     QPainter *painter = themeData.painter;
     QRectF rectF = scaleRect(QRectF(themeData.rect), additionalDevicePixelRatio);
-
+    if (themeData.partId ==  WP_MDICLOSEBUTTON)
+        qDebug() <<   __FUNCTION__ << "additionalDevicePixelRatio=" << additionalDevicePixelRatio
+                  << rectF;
     if ((themeData.rotate + 90) % 180 == 0) { // Catch 90,270,etc.. degree flips.
         rectF = QRectF(0, 0, rectF.height(), rectF.width());
     }
@@ -2953,6 +2962,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo
             {
                 const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget);
                 bool isActive = tb->titleBarState & QStyle::State_Active;
+                qDebug() << __FUNCTION__ << CC_TitleBar;
                 XPThemeData theme(widget, p, QWindowsXPStylePrivate::WindowTheme);
                 if (sub & SC_TitleBarLabel) {
 
@@ -3038,6 +3048,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo
                 if (sub & SC_TitleBarMaxButton && tb->titleBarFlags & Qt::WindowMaximizeButtonHint
                         && !(tb->titleBarState & Qt::WindowMaximized)) {
                     theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarMaxButton, widget);
+                    qDebug() << __FUNCTION__ << CC_TitleBar << "maxb"<< theme.rect;
                     partId = WP_MAXBUTTON;
                     if (widget && !widget->isEnabled())
                         stateId = MAXBS_DISABLED;
@@ -3159,6 +3170,8 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo
 
             if (option->subControls & SC_MdiCloseButton) {
                 buttonRect = proxy()->subControlRect(CC_MdiControls, option, SC_MdiCloseButton, widget);
+                qDebug() << __FUNCTION__ << CC_MdiControls << widget << "br=" << buttonRect
+                         << "size=" << theme.size();
                 if (theme.isValid()) {
                     theme.partId = WP_MDICLOSEBUTTON;
                     theme.rect = buttonRect;
@@ -3583,6 +3596,7 @@ QRect QWindowsXPStyle::subControlRect(ComplexControl cc, const QStyleOptionCompl
             break;
         }
         rect = QRect(offset, 0, buttonWidth, option->rect.height());
+        qDebug() << __FUNCTION__ << CC_MdiControls << rect << "buttonWidth" << buttonWidth << option->rect;
         break;
     }
 #endif // QT_CONFIG(mdiarea)
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index 35b630cde2..f2d7ffef41 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -3868,6 +3868,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
                     bsy = 0;
                 }
                 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiCloseButton, widget);
+                qDebug() << __FUNCTION__ << widget << btnOpt.rect;
                 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget);
                 QPixmap pm = proxy()->standardIcon(SP_TitleBarCloseButton).pixmap(qt_getWindow(widget), buttonIconSize);
                 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
@@ -4355,7 +4356,9 @@ QRect QCommonStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex
             default:
                 break;
             }
+
             ret = visualRect(tb->direction, tb->rect, ret);
+            qDebug() << __FUNCTION__ << CC_TitleBar << ret;
         }
         break;
 #if QT_CONFIG(groupbox)
@@ -4471,6 +4474,7 @@ QRect QCommonStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex
             if (opt->subControls & SC_MdiNormalButton)
                 offset += buttonWidth;
             break;
+            qDebug() << __FUNCTION__ <<CC_MdiControls <<  "buttonWidth=" << buttonWidth << "offset=" << offset;
         default:
             break;
         }
@@ -4481,6 +4485,7 @@ QRect QCommonStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex
         if (numSubControls == 1)
             --buttonWidth;
         ret = QRect(offset, 0, buttonWidth, opt->rect.height());
+        qDebug() << __FUNCTION__ << CC_MdiControls<< "rets=" <<ret;
         break;
     }
 #endif // QT_CONFIG(mdiarea)
diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp
index 685c5e159e..72a6ea464b 100644
--- a/src/widgets/widgets/qmdisubwindow.cpp
+++ b/src/widgets/widgets/qmdisubwindow.cpp
@@ -604,6 +604,9 @@ void ControllerWidget::paintEvent(QPaintEvent * /*paintEvent*/)
         opt.state |= QStyle::State_MouseOver;
     }
     QPainter painter(this);
+    qDebug() << __FUNCTION__ << "drawing" << QStyle::CC_MdiControls
+             << "dpi=" << logicalDpiX() << "dpr=" << devicePixelRatioF()
+             << "on " << parentWidget();
     style()->drawComplexControl(QStyle::CC_MdiControls, &opt, &painter, mdiArea);
 }
 
@@ -762,6 +765,7 @@ QMenuBar *QMdiSubWindowPrivate::menuBar() const
 */
 void ControlContainer::showButtonsInMenuBar(QMenuBar *menuBar)
 {
+    qDebug() << __FUNCTION__ << menuBar;
     if (!menuBar || !mdiChild || mdiChild->windowFlags() & Qt::FramelessWindowHint)
         return;
     m_menuBar = menuBar;
@@ -771,6 +775,7 @@ void ControlContainer::showButtonsInMenuBar(QMenuBar *menuBar)
         if (currentLeft)
             currentLeft->hide();
         if (currentLeft != m_menuLabel) {
+            qDebug() << __FUNCTION__ <<"1) Setting" << m_menuLabel << menuBar;
             menuBar->setCornerWidget(m_menuLabel, Qt::TopLeftCorner);
             previousLeft = currentLeft;
         }
@@ -782,6 +787,7 @@ void ControlContainer::showButtonsInMenuBar(QMenuBar *menuBar)
         if (currentRight)
             currentRight->hide();
         if (currentRight != m_controllerWidget) {
+            qDebug() << __FUNCTION__ <<"Setting m_controllerWidget" << m_controllerWidget << menuBar;
             menuBar->setCornerWidget(m_controllerWidget, Qt::TopRightCorner);
             previousRight = currentRight;
         }
@@ -3173,6 +3179,7 @@ void QMdiSubWindow::paintEvent(QPaintEvent *paintEvent)
 
     if (!d->windowTitle.isEmpty())
         painter.setFont(d->font);
+    qDebug() << __FUNCTION__ << "drawing title";
     painter.drawComplexControl(QStyle::CC_TitleBar, d->cachedStyleOptions);
 
     if (isMinimized() && !d->hasBorder(d->cachedStyleOptions))
