Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-49977

OS X: Improve QWindow embedding support

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.5
    • QPA
    • None
    • macOS

    Description

      Improve support for embedding QWindow in 'foreign' view hierarchies.

      Use cases under consideration:

      • Qt as a plugin: Qt is used to author a plugin for a native application, where the plugin typically provides a native view instance which the host application controls.
      • NSWindow configuration: There are many ways to configure a NSWindow and we can't support them all through the cross-platform Qt API. Instead the application author can configure the NSWindow they like and then embed the Qt view in it.

      Other work

      "Add foreign window internal documentation": https://codereview.qt-project.org/#/c/127152 (https://gist.github.com/torarnv/c5dfe2d2bc0c089910ce)

      Current support

      QWindow::winId()
      QMacNativeWidget

      Plans

      Make "Qt is embedded" the default case on OS X: Don't make any assumptions on what the parent view of the Qt view is. The normal configuration where Qt is control of the entire hierarchy is then a special case of this, and we seek to minimize any special handling required.

      QMacNativeWidget will be deprecated. You don't need special widget, instead you embed the top-level Widget (or more specifically the window for the top-level widget)

      Suggested Changes

      Native View Accessor API
      A safer, more convenient replacement for winId() and windowHandle().

      NSView *QWindow::nativeView()
      NSView *QWidget::nativeView()
      
      • Returns a platform-native view type (NSView on OS X, etc)
      • Creates the backing QWindow/QPlatformWindow as needed
      • Configures the platform window for “embedded mode” (if needed)
      • Transfers ownership of the QWindow to the native view. (On platforms were the native type can own things)

      Native View Accessor API V2

      NSView *QWindow::toNSView()
      static QWindow::fromNSView()
      

      https://codereview.qt-project.org/#/c/145488/

      QWidget Visibility
      We would like to control visibility from the from the platform plugin in cases where the widget is shown using native API.

      QWidget *root = new ApplicationWidget();
      NSView *view = root->nativeView();
      [[window contentView] addSubview:view];
      
      // later:
      [window makeKeyAndOrderFront];
      

      Problem: QWidget needs a setVisible(true) call to transition to the correct state where it will paint.
      Solutions:

      • Make QWidgetWindow::handleExposeEvent() force visibility.
      • Add QWindowSystemInterface::VisibilityEvent

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-49977
          # Subject Branch Project Status CR V

          Activity

            People

              vestbo Tor Arne Vestbø
              sorvig Morten Sørvig
              Veli-Pekka Heinonen Veli-Pekka Heinonen
              Votes:
              4 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes