开发者

Can I draw Qt objects directly to Win32 DC (Device Context)?

I can draw Qt objects to an QImage and then draw the image to HDC or CDC. This may hurt our application's performance. It would be great if I can draw Qt objects directly to Win32 HDC or MFC CDC. I expect that there is a class, say QWin32Image for clear, then I can use it in this way:

QWin32Image image(hdc, 100, 100, Format_ARGB32_Premultiplied)开发者_Python百科;
QPainter painter(&image);
painter.drawText(....);

Is it possible for my thought? Or is there a better way to do that?


Short answer - No. AFAIK in Qt, they abstract the entire UI for platform independence at application code level. Qt paints all of its widgets to it's own buffer and then paints to the screen.

Long answer - Qualified Yes.

Qt offers Win/MFC Integration Library which will allow Qt objects to interact with HDC and MFC objects. This library does work well. But I found using it somewhat confusing until I understood how it works.

What this library does allows you display QWindows in MFC window or MFC window in at Qt frame. As long as you keep this in mind, you can make it work.

Alternately, QImage.scanLine(0) points to the entire raw bitmap that you can use to write directly to the screen using one of the windows functions. Even though function name is scanline, using it this way points to start of the raw pixel buffer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜