I’m scratching my head here… why does this window when launched in Maya 2017 not stay on top of the main Maya window?
If you click outside this window, it’ll disappear behind the main Maya window.
I just want this window to behave like e.g. the hypershade or any other editor which floats atop Maya and doesn’t lock up the main Maya window in any way.
What did I do wrong?
from PySide2 import QtWidgets, QtCore
class ToolWindow(QtWidgets.QMainWindow):
def __init__(self):
super(ToolWindow, self).__init__()
self.setWindowFlags(QtCore.Qt.Tool)
self.widget = QtWidgets.QWidget()
self.layout = QtWidgets.QVBoxLayout()
self.button = QtWidgets.QPushButton('Yoghurt')
self.layout.addWidget(self.button)
self.widget.setLayout(self.layout)
self.setCentralWidget(self.widget)
window = ToolWindow()
window.show()
// Fredrik
Sorry… managed to copy-paste the wrong code where I didn’t parent to the MayaWindow. Still can’t make it to work though, so any input is greatly appreciated!
from PySide2 import QtWidgets, QtCore
def _maya_main_window():
"""Return Maya's main window"""
for obj in QtWidgets.qApp.topLevelWidgets():
if obj.objectName() == 'MayaWindow':
return obj
raise RuntimeError('Could not find MayaWindow instance')
class ToolWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(ToolWindow, self).__init__()
self.setWindowFlags(QtCore.Qt.Tool)
self.widget = QtWidgets.QWidget()
self.layout = QtWidgets.QVBoxLayout()
self.button = QtWidgets.QPushButton('Yoghurt'
)
self.layout.addWidget(self.button)
self.widget.setLayout(self.layout)
self.setCentralWidget(self.widget)
window = ToolWindow(parent=_maya_main_window())
window.show()
Argh.. ok, here's a gist instead:
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWNX6ksPR6O0rVCuOjbwPyCq_tpj-jQq66v0vgY3Z%2BU9cg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Just tried it on my mac and it worked fine when the Qt.Tool flag was set
Hi Johan, yeah - that’s what I found was weird too. It works when the flag is set in Maya on OS X, but not in Maya on Windows.
You aren’t actually passing the parent argument from your own constructor to the superclass constructor. Is that still a typo?
If it is a typo and you are properly passing the parent, try moving the Tool window flag into the superclass constructor call as well, instead of calling it afterwards.
Hey Justin, hm… what typo were you referring to?
I mistakenly copy-pasted the wrong code in my initial email, if that's what you meant. The gist is here.
I tried also doing a super(ToolWindow, self).setWindowFlags(QtCore.Qt.Tool)
but that didn’t change anything. Is that what you meant?
// Fredrik
Just tried it on my mac and it worked fine when the Qt.Tool flag was set
Hi Johan, yeah - that’s what I found was weird too. It works when the flag is set in Maya on OS X, but not in Maya on Windows.
You aren’t actually passing the parent argument from your own constructor to the superclass constructor. Is that still a typo?
If it is a typo and you are properly passing the parent, try moving the Tool window flag into the superclass constructor call as well, instead of calling it afterwards.Hey Justin, hm… what typo were you referring to?
I mistakenly copy-pasted the wrong code in my initial email, if that's what you meant. The gist is here.
I tried also doing a
super(ToolWindow, self).setWindowFlags(QtCore.Qt.Tool)
but that didn’t change anything. Is that what you meant?
// Fredrik
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWOa3wJe-pVw9QD8rSSOpaoJyhKzHGpNLf7SEGTG2M%2B8yw%40mail.gmail.com.
Ahhh, as always, spot on Justin :)
Thanks. This did the trick:
super(ToolWindow, self).__init__(parent)
Updated gist here:
https://gist.github.com/fredrikaverpil/b76bd91b9924435465ecb1b2270c1a9d
What’s weird is now that you must set the Qt.Tool window flag in OS X to make the window stay on top of Maya. In Windows, you don’t have to use this window flag…
// Fredrik
Ahhh, as always, spot on Justin :)
Thanks. This did the trick:
super(ToolWindow, self).__init__(parent)
Updated gist here:
https://gist.github.com/fredrikaverpil/b76bd91b9924435465ecb1b2270c1a9dWhat’s weird is now that you must set the Qt.Tool window flag in OS X to make the window stay on top of Maya. In Windows, you don’t have to use this window flag…
--// Fredrik
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWNMa%2BzAVmDHLX9iVBQiQ4supNeJ%3DU8Um8Y1gg9APNcL3A%40mail.gmail.com.
Managed to get help from Autodesk on this. Apparantly, the following code makes Maya cast some black magic on the window and bless it with being properly float on top of the main Maya window without the Qt.Tool flag:
self.setProperty("saveWindowPref", True)
Figured I’d just share my findings on this:
https://gist.github.com/fredrikaverpil/b76bd91b9924435465ecb1b2270c1a9d
In the gist there are various ways of making a cross-platform floating window. The code is for PySide2 but can easily be ported to PySide.
Cheers!
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWMNKUF-xSr1FVWjkpDjDk%3DTv1ES1g4KEhkmb1yBg1MnGQ%40mail.gmail.com.
Thanks for this info. Part of their customizations to Qt I take it.
Yeah, must be.
The part about actually saving window positions… Is that between layout changes or something? I didn’t think that would refer to Maya startup since your window wouldn’t exist by the time Maya went to restore prefs. Unless it is more black magic that records the object name and catches the new window creation when you do it?
I does record the object name and require you set one for Maya to remember its position. There’s definitively some “black magic” involved.
// Fredrik