Skip to content

Instantly share code, notes, and snippets.

@redglasses67
Last active June 15, 2020 13:37
Show Gist options
  • Select an option

  • Save redglasses67/7b116c010085ad93ce5b76ccc7c28d7b to your computer and use it in GitHub Desktop.

Select an option

Save redglasses67/7b116c010085ad93ce5b76ccc7c28d7b to your computer and use it in GitHub Desktop.
Maya上のウィンドウを画面の中心に集める
# -*- coding: utf-8 -*-
"""
参考サイト
python - PyQt4 center window on active screen - Stack Overflow
https://stackoverflow.com/questions/20243637/pyqt4-center-window-on-active-screen
getting all QT/PySide Windows - Google グループ
https://groups.google.com/forum/#!topic/python_inside_maya/q245Vh6W7uI
"""
try:
from PySide2.QtWidgets import QApplication
except ImportError:
from PySide.QtGui import QApplication
desktop = QApplication.desktop()
activeScreen = desktop.screenNumber(desktop.cursor().pos())
desktopCenter = desktop.screenGeometry(activeScreen).center()
topWindows = QApplication.topLevelWidgets()
for topWin in topWindows:
# topWin.parent() がないとMayaのメインウィンドウまで取得してしまう
if topWin.isWindow() and not topWin.isHidden() and topWin.parent():
windowCenter = topWin.rect().center()
topWin.move(desktopCenter - windowCenter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment