问题
I have a Windows HDC handle from an external library that I'd like to use QPainter functionality to draw on. Is there any way in Qt to create a QPaintDevice from a HDC handle?
回答1:
One way of doing this:
Using the Windows API, get the HWND from the HDC.
HWND handle = WindowFromDC(hdc);
assert(handle != NULL);
Then subclass QWidget to get access to the protected member convert. Using this, create the QWidget using this member as described in this solution: How to create a qwidget with a hwnd as parent. In this example, I've called the subclass for QWidgetWrapper.
QWidgetWrapper *w = new QWidgetWrapper();
w->create((Wld)main_window);
Note that Wld is a typedef in Qt for "Platform dependent window identifier".
来源:https://stackoverflow.com/questions/10373429/create-a-qpaintdevice-from-hdc-handle