从HDC句柄创建QPaintDevice [英] Create a QPaintDevice from HDC handle

查看:1328
本文介绍了从HDC句柄创建QPaintDevice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自外部库的Windows HDC句柄,我想使用QPainter功能来绘制。在Qt中有什么办法从HDC句柄创建QPaintDevice?

解决方案



使用Windows API从HDC获取HWND。

  HWND handle = WindowFromDC(hdc); 
assert(handle!= NULL);

然后再子类化QWidget以访问受保护的成员convert。使用此,使用此成员如此解决方案中所述创建QWidget:如何创建一个带有hwnd作为父类的qwidget 。在这个例子中,我为QWidgetWrapper调用了子类。

  QWidgetWrapper * w = new QWidgetWrapper 
w-> create((Wld)main_window);

注意,Wld是平台相关窗口标识符的Qt中的typedef。


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?

解决方案

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".

这篇关于从HDC句柄创建QPaintDevice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆