Skip to content

Instantly share code, notes, and snippets.

@tpoveda
Created March 26, 2021 01:51
Show Gist options
  • Save tpoveda/03640e6df309006c04d588156eb94db0 to your computer and use it in GitHub Desktop.
Save tpoveda/03640e6df309006c04d588156eb94db0 to your computer and use it in GitHub Desktop.
MotionBuilder - Custom Menu
# Creates a new QMenu and attaches to main MotionBuilder menu bar
try:
from PySide2.QtWidgets import QApplication, QMenuBar, QMenu, QAction
except ImportError:
from PySide.QtGui import QApplication, QMenuBar, QMenu, QAction
def get_main_qt_window():
parent = QApplication.activeWindow()
grand_parent = parent
while grand_parent is not None:
parent = grand_parent
grand_parent = parent.parent()
return parent
main_widget = get_main_qt_window()
menubar = main_widget.findChild(QMenuBar)
custom_menu = QMenu('Custom Menu')
action = QAction('Hello World', custom_menu)
custom_menu.addAction(action)
menubar.addMenu(custom_menu)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment