[Qt-interest] Hosting plug-in UIs within Qt application

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Fri Jun 25 11:37:40 CEST 2010


Glenn Hughes wrote on Friday, June 25, 2010 5:20 AM:

> ...
> So, I need to know a few things about how Qt manages the drawing
> environment, and how to get at the underlying OS objects. 

So I understand your plugins are expected to be non-Qt plugins, with their native (Carbon/Cocoa on Mac, GDI on Windows etc.) drawing code?

Otherwise it would be totally easy: your plugins provide a method which would return a reference to a QWidget, your main app would place this widget into its mainwindow (or wherever - whenever the plugin is "selected" or "becomes active") and the plugins would happily paint with a QPainter into their QWidget (which would automatically get the proper "update" events by the Qt event queue, whenever it becomes visible/resized etc.).
 
> 1) How does Qt set up the port and the origin when drawing under
> Carbon? Is there a way to tell Qt that the port and origin are
> "dirty"  
> and need to be reset?
> 2) How can I get at the port (CGrafPtr or CGContextRef) on the Mac?
> 3) How can I get an HDC under Windows?

I have absolutely no clue for 1) and 2) (one of the major reasons I use Qt - I don't /want/ to know about these things ;), but here are a few pointers:

http://doc.trolltech.com/4.6/qwidget.html#winId 
http://doc.trolltech.com/4.6/qwidget.html#getDC - on Windows I think this is what returns you the HDC
http://doc.trolltech.com/4.6/qx11embedwidget.html - allows you to embed an X11 (non-Qt) widget on X11 - does not answer your question, but might give you some ideas.

Then I found this googling for "embed native cocoa widgets into qt application": http://www-sop.inria.fr/dream/blog/2009/03/mixing-cocoa-and-qt-through-carbon/ - "This post shows how to use Cocoa within a Qt application through Carbon." Sounds a bit weird, I did not go into details, but might give you some pointers, too.

On Windows I think embedding "native" widgets should be possible, too, as long as you have the native HDC and/or "WinId" (winId() and Co.) and pass this in as "parent" for your native Window widgets.

I have never done "embedding native widgets into Qt" (on Windows "ActiveQt" allows you to embed "ActiveX" components, might also be worth reading that documentation or check out the corresponding Qt code how they embed those widgets), so take this as "hints and leads", rather than concrete tips.


Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list