views:

176

answers:

1

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);
QPainter painter(&image);
painter.drawText(....);

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

+2  A: 

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.

photo_tom
What windows functions can be used for this end? QPixmap can convert QImage to windows bitmap handle: QPixmap::fromImage(image).toWinHBITMAP(QPixmap::PremultipliedAlpha), which approach is better considering the performance?
Kevin C.
Don't have a lot of experience in doing this. In our app we've been using QImage.scanLine(0) to directly manipulate the raw pixel buffer with the Intel Performance Primitives Library as this fits our application better. My experience has been, the fewer conversions you have to do, the better. Especially in debug mode as QImage and QPixmap can be very slow sometimes. Release mode doesn't have this problem though.
photo_tom