diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp
index d900e4d..89adf70 100644
--- a/src/widgets/styles/qwindowsvistastyle.cpp
+++ b/src/widgets/styles/qwindowsvistastyle.cpp
@@ -415,12 +415,13 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
         {
             XPThemeData theme(widget, painter, QWindowsXPStylePrivate::TreeViewTheme);
             static int decoration_size = 0;
-            if (!decoration_size && d->initTreeViewTheming() && theme.isValid()) {
+            if (!decoration_size && d->initTreeViewTheming() && theme.isValid()) {                
                 XPThemeData themeSize = theme;
                 themeSize.partId = TVP_HOTGLYPH;
                 themeSize.stateId = GLPS_OPENED;
                 const QSize size = themeSize.size() / QWindowsXPStylePrivate::devicePixelRatio(widget);
                 decoration_size = qMax(size.width(), size.height());
+                qDebug() << __FUNCTION__  << "okdecoration_size=" << decoration_size;
             }
             int mid_h = option->rect.x() + option->rect.width() / 2;
             int mid_v = option->rect.y() + option->rect.height() / 2;
@@ -2471,6 +2472,7 @@ bool QWindowsVistaStylePrivate::initTreeViewTheming()
         return true;
 
     m_treeViewHelper = createTreeViewHelperWindow();
+
     if (!m_treeViewHelper) {
         qWarning("Unable to create the treeview helper window.");
         return false;
@@ -2480,7 +2482,9 @@ bool QWindowsVistaStylePrivate::initTreeViewTheming()
         qErrnoWarning("SetWindowTheme() failed.");
         return false;
     }
-    return QWindowsXPStylePrivate::createTheme(QWindowsXPStylePrivate::TreeViewTheme, m_treeViewHelper);
+    HTHEME ht =QWindowsXPStylePrivate::createTheme(QWindowsXPStylePrivate::TreeViewTheme, m_treeViewHelper);
+    qDebug() << __FUNCTION__ << "m_treeViewHelper" << m_treeViewHelper << "explorer/tv theme=" << ht;
+    return ht;
 }
 
 void QWindowsVistaStylePrivate::cleanupTreeViewTheming()
diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp
index 5b01312..6473243 100644
--- a/src/widgets/styles/qwindowsxpstyle.cpp
+++ b/src/widgets/styles/qwindowsxpstyle.cpp
@@ -162,6 +162,8 @@ static const wchar_t *themeNames[QWindowsXPStylePrivate::NThemes] =
 
 static inline QBackingStore *backingStoreForWidget(const QWidget *widget)
 {
+    if (!widget)
+        return 0;
     if (QBackingStore *backingStore = widget->backingStore())
         return backingStore;
     if (const QWidget *topLevel = widget->nativeParentWidget())
@@ -235,6 +237,16 @@ HRGN XPThemeData::mask(QWidget *widget)
     return hrgn;
 }
 
+
+QDebug operator<<(QDebug d, const XPThemeData &td)
+{
+    d << "XPThemeData(" <<  td.widget << "painter=" << td.painter
+      << "theme=" << td.theme << "htheme=" << td.htheme << "partId" << td.partId
+      << "stateId=" << td.stateId << td.rect << "trans" << td.mirrorHorizontally << td.mirrorVertically
+      << td.noBorder << td.noContent << td.rotate << ')';
+    return d;
+}
+
 // QWindowsXPStylePrivate -------------------------------------------------------------------------
 // Static initializations
 QPixmap *QWindowsXPStylePrivate::tabbody = 0;
@@ -344,6 +356,14 @@ HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd)
     if (!m_themes[theme]) {
         const wchar_t *name = themeNames[theme];
         m_themes[theme] = pOpenThemeData(hwnd, name);
+        if (theme == TreeViewTheme) {
+            char buf[200] = {0};
+            GetClassNameA(hwnd, buf, 200);
+            if (strcmp(buf, "QTreeViewThemeHelperWindowClass"))
+                qDebug("XXX!");
+            qDebug() << __FUNCTION__ << "hwnd=" << hwnd << buf << QString::fromWCharArray(name) << m_themes[theme];
+        }
+
         if (!m_themes[theme])
             qErrnoWarning("OpenThemeData() failed for theme %d (%s).",
                           theme, qPrintable(themeName(theme)));
@@ -759,6 +779,11 @@ bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData)
     }
 
     const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : HDC(0);
+    if (themeData.partId == TVP_HOTGLYPH || themeData.partId == TVP_GLYPH) {
+        qDebug() << __FUNCTION__ << "dc=" << dc << themeData.widget
+                 << "backstor=" << backingStoreForWidget(themeData.widget)
+                 << themeData;
+    }
     const bool result = dc ? drawBackgroundDirectly(themeData) : drawBackgroundThruNativeBuffer(themeData);
     painter->restore();
     return result;
@@ -775,6 +800,14 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(XPThemeData &themeData)
     HDC dc = 0;
     if (themeData.widget)
         dc = hdcForWidgetBackingStore(themeData.widget);
+    if (!dc)
+        qDebug() << __FUNCTION__ << "DC0!";
+
+    if (themeData.partId == TVP_HOTGLYPH || themeData.partId == TVP_GLYPH) {
+        qDebug() << __FUNCTION__ << "dc=" << dc << themeData.widget
+                 << "backstor=" << backingStoreForWidget(themeData.widget)
+                 << themeData;
+    }
 
     QPoint redirectionDelta(int(painter->deviceMatrix().dx()),
                             int(painter->deviceMatrix().dy()));
@@ -806,7 +839,12 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(XPThemeData &themeData)
                           | (themeData.mirrorHorizontally ? DTBG_MIRRORDC : 0);
 
     if (pDrawThemeBackgroundEx != 0) {
-        pDrawThemeBackgroundEx(themeData.handle(), dc, themeData.partId, themeData.stateId, &(drawRECT), &drawOptions);
+        HTHEME ht = themeData.handle();
+        if (themeData.partId == TVP_HOTGLYPH || themeData.partId == TVP_GLYPH)
+            qDebug() << "HTHEME=" << ht;
+        HRESULT hr = pDrawThemeBackgroundEx(ht, dc, themeData.partId, themeData.stateId, &(drawRECT), &drawOptions);
+        if (FAILED(hr))
+            qErrnoWarning("pDrawThemeBackgroundEx");
     } else {
         // We are running on a system where the uxtheme.dll does not have
         // the DrawThemeBackgroundEx function, so we need to clip away
diff --git a/src/widgets/styles/qwindowsxpstyle_p_p.h b/src/widgets/styles/qwindowsxpstyle_p_p.h
index e1e1369..4a5cd14 100644
--- a/src/widgets/styles/qwindowsxpstyle_p_p.h
+++ b/src/widgets/styles/qwindowsxpstyle_p_p.h
@@ -185,6 +185,9 @@ QT_BEGIN_NAMESPACE
 
 #if !defined(QT_NO_STYLE_WINDOWSXP)
 
+
+class QDebug;
+
 // Declarations -----------------------------------------------------------------------------------
 class XPThemeData
 {
@@ -228,6 +231,8 @@ public:
     QRect rect;
 };
 
+QDebug operator<<(QDebug d, const XPThemeData &td);
+
 struct ThemeMapKey {
     int theme;
     int partId;
