--
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/6bcd74b5-9996-4b50-835f-7fdbe724e0ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCCLN-V6LitW_5C-%2BGbC1AXCUUQbKPt4QON28pkDKK7gg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/56F15823.3000109%40gmail.com.
I’ve had a look at this just now, and it looks like they’ve gone from using a QToolBox to simply appending arbitrary widgets to a QLayout.
I don’t blame them, think it should probably have been made that way from the start, but what it means for us is that there is no adapting this script to work. It’ll need a rewrite.
It’s possible the alternative approach could work on 2017 and lower, which would be ideal.
I would start looking into grabbing hold of the layout, and adding your widget (not action) to it.
Here’s a start.
import os
try:
from PySide import QtGui
QtWidgets = QtGui
except ImportError:
from PySide2 import QtWidgets, QtGui
# Use this to locate your widget; it will return the
# widget currently under your cursor.
# parent = QtWidgets.qApp.widgetAt(QtGui.QCursor.pos()).objectName()
# parent.objectName()
# Use this once you know the name of it, in this case "toolBar1"
# We can find it as a child of the main window.
window = {o.objectName(): o for o in QtWidgets.qApp.topLevelWidgets()}["MayaWindow"]
toolbar = window.findChild(QtWidgets.QToolBar, "toolBar1")
if toolbar:
layout = toolbar.layout()
else:
layout = window.findChild(QtWidgets.QLayout, "flowLayout1")
assert layout, "Sorry, couldn't find the toolbar."
# Create a random action
# NOTE: Not including an icon
action = QtWidgets.QPushButton("Hello")
# Add to the end..
# NOTE: Not adding to start
layout.addWidget(action)
# If you need to replace/update it, you can remove it like so.
# action.deleteLater()
# Enjoy!
--
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_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5bc42682-b2ca-45e8-b617-360dd2b3b07e%40googlegroups.com.
Ah, that’s interesting.
qApp
is the actively running instance of a QApplication; you could alternatively call QtWidgets.QApplication.instance()
. Maya is bound to have just one, but it seems that, based on your description, userSetup.py
executes before Qt starts running (sometimes?).
I would pass the entire thing, e.g. by wrapping it into a function, through cmds.evalDeferred
or Qt.QtCore.QTimer.singleShot
, that should give Qt enough time to catch up.