1
votes

I am trying to parent a QMainWindow to a non-qt application (the application may change). Any ideas on how to do this?

The qt window opens fine and i can interact with the python API in the applications however the qt window goes behind the application window if i click on the application. I could use Qt.WindowStaysOnTopHint flag but then it's on top of everything which isn't ideal.

Psuedo Example: If you were using an application (example Nuke) where the main application is also qt based you would use something like:

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

wdg = myWidget(parent=_nuke_main_window())
wdg.show()

Maya and any other pyqt based window also would work similarly.

However if the application isnt qt based:

wdg = myWidget(parent=nonQtWindowQt_ised)
wdg.show()

where:

def nonQtWindowQt_ised():
    #return the application main window somehow maybe through python bindings like SIP?

Any examples (ideally) or useful direction would be much appreciated.

Using PyQt5, Python 3.5 and Linux.

Your current question can be described as too broad, or why is not this code working? so if you do not give specific details is not suitable for SO.eyllanesc
Sorry, updated. I thought for qt people it would make more sense perhaps.Mafster
What information do you have about the non-Qt application? Its native window id?G.M.
The only available qt api seems to be setTransientParent. However, it doesn't appear to be very reliable (see e.g. QTBUG-55669), and I couldn't get it to work on my linux system at all. What you need is some linux utility that can reliably set WM_TRANSIENT_FOR, but I don't know of any myself.ekhumoro