Skip to content
This repository has been archived by the owner on Aug 20, 2023. It is now read-only.

Window will not stay on top of Nuke (OS X) without Qt.Tool or Qt.WindowStaysOnTopHint #12

Open
fredrikaverpil opened this issue Jan 15, 2017 · 0 comments

Comments

@fredrikaverpil
Copy link
Owner

On Mac OS X, I was unable to get the floating window to always stay on top of Nuke. If you click in the main Nuke window, the floating window would disappear behind the main Nuke window.

I reached out to the Foundry:

I'm creating a simple window with PySide and I parent it to the main Nuke application. In Windows this window will always stay on top of Nuke even if I click the main Nuke window.

In OS X however (and I assume perhaps also on Linux), if I click the Nuke window, my PySide window disappears behind Nuke. Why is that and can that be fixed?

Please note, I wish to keep the fullscreen/maximize/minimize window controls, so I'm not interested in setting the window flags to either Qt.Tool or Qt.WindowStaysOnTopHint.

Regards,
Fredrik

from PySide import QtGui, QtCore


class Boilerplate(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(Boilerplate, self).__init__(parent)

        # Set object name and window title
        self.setObjectName('hello')
        self.setWindowTitle('hello world!')

        # Window type (I don't want Qt.Tool)
        self.setWindowFlags(QtCore.Qt.Window)

        # Set the main widget
        self.main_widget = QtGui.QLabel('Hello world!')
        self.setCentralWidget(self.main_widget)


def _nuke_main_window():
    """Returns Nuke's main window"""
    for obj in QtGui.qApp.topLevelWidgets():
        if (obj.inherits('QMainWindow') and
                obj.metaObject().className() == 'Foundry::UI::DockMainWindow'):
            return obj
    else:
        raise RuntimeError('Could not find DockMainWindow instance')


my_window = Boilerplate(parent=_nuke_main_window())
my_window.show()  # Show the UI

This was the response from The Foundry:

This is really difficult to solve unfortunately. The Qt documentation for QWidget says that parenting a window to another will make it float above the other window, but the documentation is wrong and the behaviour is dependent on the window management policy for your platform. Having a floating window which doesn't get hidden when the application goes to the background is deemed un-Mac-like behaviour and not allowed. The only ways to get windows to float are to use Qt.Tool or Qt.WindowStaysOnTopHint which both have problems. In particular, Qt.WindowStaysOnTopHint makes the window stay on top of all windows even when the application is in the background. Nuke gets round this problem by manipulating the Qt.WindowStaysOnTopHint during application activation and deactivation, but to do this correctly requires writing Objective-C code and can't be done from Python (the equivalent Qt events don't get delivered at the correct time for this).

Possible solutions are:

Use Qt.Tool (I know this has already been dismissed, but it's here for completeness. Nuke does make sure that Qt.Tool windows don't get hidden when the application is deactivated, but you do lose the maximize/minimize buttons
Use the Nuke APIs to register the window as a panel, This will allow the window to be docked but also make it float correctly. I'm not sure if it solves the maximize/minimize buttons though.

So, as a workaround, the boilerplate is now setting the windows flag Qt.Tool, as I believe this a bit better than setting Qt.WindowStaysOnTopHint.

Unfortunately, there seems to be no way around this as for now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant