From d96bf490a0342a31343ffc88c34b715675638118 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 24 Apr 2013 14:09:14 +0200 Subject: setEmbeddedInForeignView to embed a QWindow in a foreign window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Depends on https://codereview.qt-project.org/#change,54607 in qtbase Change-Id: Id95038b0a6f3383358a4d688ee2c5e6907ebe7c0 Reviewed-by: Morten Johan Sørvig --- examples/embeddedqwindow/main.mm | 14 +++++++------- examples/embeddedqwindow/window.cpp | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'examples') diff --git a/examples/embeddedqwindow/main.mm b/examples/embeddedqwindow/main.mm index 89ae8b8..810d789 100644 --- a/examples/embeddedqwindow/main.mm +++ b/examples/embeddedqwindow/main.mm @@ -50,17 +50,17 @@ NSView *getEmbeddableView(QWindow *qtWindow) { - // Set Qt::SubWindow flag. Should be done before crate() is - // called - if you call create() or caused it ot be called - // before calling this function you need to set SubWindow - // yourself - qtWindow->setFlags(qtWindow->flags() | Qt::SubWindow); - // Make sure the platform window is created qtWindow->create(); - // Get the Qt content NSView for the QWindow forom the Qt platform plugin QPlatformNativeInterface *platformNativeInterface = QGuiApplication::platformNativeInterface(); + + // Inform the window that it's a "guest" of a non-QWindow + typedef void (*SetEmbeddedInForeignViewFunction)(QPlatformWindow *window, bool embedded); + reinterpret_cast(platformNativeInterface-> + nativeResourceFunctionForIntegration("setEmbeddedInForeignView"))(qtWindow->handle(), true); + + // Get the Qt content NSView for the QWindow from the Qt platform plugin NSView *qtView = (NSView *)platformNativeInterface->nativeResourceForWindow("nsview", qtWindow); return qtView; // qtView is ready for use. } diff --git a/examples/embeddedqwindow/window.cpp b/examples/embeddedqwindow/window.cpp index 8ae918c..1868591 100644 --- a/examples/embeddedqwindow/window.cpp +++ b/examples/embeddedqwindow/window.cpp @@ -59,6 +59,7 @@ QColor colorTable[] = Window::Window(QScreen *screen) : QWindow(screen) , m_backgroundColorIndex(colorIndexId++) + , m_backingStore(0) { initialize(); } @@ -66,6 +67,7 @@ Window::Window(QScreen *screen) Window::Window(QWindow *parent) : QWindow(parent) , m_backgroundColorIndex(colorIndexId++) + , m_backingStore(0) { initialize(); } @@ -181,6 +183,8 @@ void Window::timerEvent(QTimerEvent *) void Window::render() { + if (!m_backingStore) + return; QRect rect(QPoint(), geometry().size()); m_backingStore->resize(rect.size()); -- cgit v1.2.3