import maya.OpenMayaUI as omui
try:
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2 import __version__
from shiboken2 import wrapInstance
except ImportError:
from PySide.QtCore import *
from PySide.QtGui import *
from PySide import __version__
from shiboken import wrapInstance
# Get the main window as a widget
omui.MQtUtil.mainWindow()
ptr = omui.MQtUtil.mainWindow()
mainWindow_widget = wrapInstance(int(ptr), QWidget)
children = mainWindow_widget.findChildren(QWidget)
# Iterate through the list to find the toolbar widget
for child in children:
if isinstance(child, QToolBar):
toolbar = child
break
children[1].setStyleSheet("background-color: red;")
A bit hacky, but you can get the button using pyside and then set it's background color 🙂