Last active
June 15, 2020 13:37
-
-
Save redglasses67/7b116c010085ad93ce5b76ccc7c28d7b to your computer and use it in GitHub Desktop.
Maya上のウィンドウを画面の中心に集める
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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