David C
David C

Reputation: 21

Mixing Qt and Cocoa via QMacNativeWidget- I'm having trouble showing a QDialog over an NSWindow

I am working on a plugin for a Cocoa application, and in order to use existing cpp code we decided to marry the Cocoa plugin with our existing Qt project via Objective-C++, which has been a lot to learn on the fly but is coming along well.

Anyways, I am stumped by my current problem. The design of this plugin is such that the application gives us an NSWindow with two NSViews inside it. We place a QMacNativeWidget which inside one of these two views, and everything there works fine. The problem that I am having is that when I try to create a new QDialog() from within our plugin, the QDialog is always behind the NSWindow containing the plugin.

Regardless of whether or not I raise() the new QDialog, the NSWindow is always in front even though it immediately loses keyboard focus to the QDialog. If I move the NSWindow I can see the QDialog behind it, but even when I click on its titlebar and move it around, it is still behind the NSWindow.

Was just wondering if anyone has had any similar problems with mixing NSWindows and QDialogs, and if there is any possible solution other than wrapping my QDialog in another QMacNativeWidget and then placing it in another NSWindow, which I would rather not have to do because I have many dialogs.

Thanks.

Upvotes: 2

Views: 1373

Answers (1)

Garvan Keeley
Garvan Keeley

Reputation: 187

I am doing something similar (Qt as a plugin to a native Cocoa app). I construct my modal QDialog with a null parent, and it behaves application modal and stays on top. Is your problem specific to having a non-modal QMacNativeWidget and a modal QDialog on top? I'm not sure I have that exact scenario. Are you setting the QDialog to have a null parent?

As a workaround you could try modifying window flags to enforce top-most behaviour:

// Qt::Tool to stay on top
QDialog* d= new QDialog(0, Qt::Tool);
// And stop the tool window from disappearing on hide
d->setAttribute(Qt::WA_MacAlwaysShowToolWindow);

See http://doc.qt.nokia.com/latest/qt.html#WindowType-enum

Alternatively, you could try NSWindow setLevel, given a QDialog 'd' (I'm skipping some casting here):

[[d->winId() window] setLevel:some_level]

Upvotes: 1

Related Questions