最近我偶然发现了QMacNativeWidget(src和header),它基本上可以在本机Cocoa应用程序中使用Qt小部件而无需使用QApplication。
现在我想知道是否有可能采用这种技术将Qt小部件嵌入到其他GUI工具包中,比如我想将QWidget Foo
放在CoolUIKit Bar
内。一眼就看出这很简单,例如主要功能是正确调整getEmbeddableView
:
NSView *getEmbeddableView(QWindow *qtWindow)
{
// Make sure the platform window is created
qtWindow->create();
// Inform the window that it's a subwindow of a non-Qt window. This must be
// done after create() because we need to have a QPlatformWindow instance.
// The corresponding NSWindow will not be shown and can be deleted later.
extern QPlatformNativeInterface::NativeResourceForIntegrationFunction resolvePlatformFunction(const QByteArray &functionName);
typedef void (*SetEmbeddedInForeignViewFunction)(QPlatformWindow *window, bool embedded);
reinterpret_cast<SetEmbeddedInForeignViewFunction>(resolvePlatformFunction("setEmbeddedInForeignView"))(qtWindow->handle(), true);
// Get the Qt content NSView for the QWindow from the Qt platform plugin
QPlatformNativeInterface *platformNativeInterface = QGuiApplication::platformNativeInterface();
NSView *qtView = (NSView *)platformNativeInterface->nativeResourceForWindow("nsview", qtWindow);
return qtView; // qtView is ready for use.
}
但是:我如何从NSView
到CoolUIKit
?或者有一种完全替代的方法吗?