summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/kernel/qwidget_win.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp
index 3fdc00c834..8a400cded2 100644
--- a/src/gui/kernel/qwidget_win.cpp
+++ b/src/gui/kernel/qwidget_win.cpp
@@ -49,6 +49,7 @@
#include "qlayout.h"
#include "qpainter.h"
#include "qstack.h"
+#include "qthread.h"
#include "qt_windows.h"
#include "qwidget.h"
#include "qwidget_p.h"
@@ -1636,6 +1637,8 @@ void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r)
}
}
+extern Q_GUI_EXPORT HDC qt_win_display_dc();
+
int QWidget::metric(PaintDeviceMetric m) const
{
Q_D(const QWidget);
@@ -1645,7 +1648,8 @@ int QWidget::metric(PaintDeviceMetric m) const
} else if (m == PdmHeight) {
val = data->crect.height();
} else {
- HDC gdc = GetDC(0);
+ bool ownDC = QThread::currentThread() != qApp->thread();
+ HDC gdc = ownDC ? GetDC(0) : qt_win_display_dc();
switch (m) {
case PdmDpiX:
case PdmPhysicalDpiX:
@@ -1696,7 +1700,8 @@ int QWidget::metric(PaintDeviceMetric m) const
val = 0;
qWarning("QWidget::metric: Invalid metric command");
}
- ReleaseDC(0, gdc);
+ if (ownDC)
+ ReleaseDC(0, gdc);
}
return val;
}