macOS: Apply QWindow properties to NSWindow when setting content view
The main responsibility of QCocoaWindow::recreateWindowIfNeeded() is to decide if the platform window is top level or not, and if so needs an NSWindow or NSPanel accompanying it. Once that decision has been made, and we've created an NSWindow or NSPanel, and made the view the content view of this window, we need to apply the QWindow properties to the newly created NSWindow or NSPanel. But doing so in recreateWindowIfNeeded increases the complexity and responsibilities of the function, so we move the logic to [QNSWindow setContentView:] instead. This is analogous to applying the properties during [QNSWindow init], but since we are now the content view we can use the same code paths to apply the initial properties as we use when they are updated later on. Change-Id: Idb4c812f4b22a029030bf4638357cf8628caea40 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> (cherry picked from commit 90d7fd58229d3b3fe04762ac53f686748c10a723) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
a17af86ae4
commit
b1ae3380c7
@ -1511,15 +1511,7 @@ void QCocoaWindow::recreateWindowIfNeeded()
|
||||
|
||||
if (isEmbeddedView) {
|
||||
// An embedded window doesn't have its own NSWindow.
|
||||
} else if (!parentWindow) {
|
||||
// QPlatformWindow subclasses must sync up with QWindow on creation:
|
||||
propagateSizeHints();
|
||||
setWindowFlags(window()->flags());
|
||||
setWindowTitle(window()->title());
|
||||
setWindowFilePath(window()->filePath()); // Also sets window icon
|
||||
setWindowState(window()->windowState());
|
||||
setOpacity(window()->opacity());
|
||||
} else {
|
||||
} else if (parentWindow) {
|
||||
// Child windows have no NSWindow, re-parent to superview instead
|
||||
[parentCocoaWindow->m_view addSubview:m_view];
|
||||
[m_view setHidden:!window()->isVisible()];
|
||||
|
@ -196,6 +196,28 @@ static bool isMouseEvent(NSEvent *ev)
|
||||
return m_platformWindow;
|
||||
}
|
||||
|
||||
- (void)setContentView:(NSView*)view
|
||||
{
|
||||
[super setContentView:view];
|
||||
|
||||
if (!qnsview_cast(self.contentView))
|
||||
return;
|
||||
|
||||
// Now that we're the content view, we can apply the properties of
|
||||
// the QWindow. We do this here, instead of in init, so that we can
|
||||
// use the same code paths for setting these properties during
|
||||
// NSWindow initialization as we do when setting them later on.
|
||||
const QWindow *window = m_platformWindow->window();
|
||||
qCDebug(lcQpaWindow) << "Reflecting" << window << "state to" << self;
|
||||
|
||||
m_platformWindow->propagateSizeHints();
|
||||
m_platformWindow->setWindowFlags(window->flags());
|
||||
m_platformWindow->setWindowTitle(window->title());
|
||||
m_platformWindow->setWindowFilePath(window->filePath()); // Also sets window icon
|
||||
m_platformWindow->setWindowState(window->windowState());
|
||||
m_platformWindow->setOpacity(window->opacity());
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
NSMutableString *description = [NSMutableString stringWithString:[super description]];
|
||||
|
Loading…
x
Reference in New Issue
Block a user