Details
-
Task
-
Resolution: Done
-
P3: Somewhat important
-
None
-
6.5
-
None
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
- is required for
-
QTBUG-49827 Qt on macOS Graphics/integration update
- Closed
For Gerrit Dashboard: QTBUG-49977 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
145488,4 | WIP: QWindow: add toNSView() and transferToNSView() | dev | qt/qtbase | Status: DEFERRED | -2 | 0 |
145619,1 | WIP: OS X: Add QWindow::fromNSView() | dev | qt/qtbase | Status: ABANDONED | -2 | 0 |
145620,1 | WIP: OS X: Add QWidget::toNSView() | dev | qt/qtbase | Status: ABANDONED | -2 | 0 |
167734,4 | Cocoa: Add transferToNativeView() internal API | 5.8 | qt/qtbase | Status: ABANDONED | +2 | 0 |