PyQt4 center window on active screen

前端 未结 4 1953
无人及你
无人及你 2020-12-28 19:21

How I can center window on active screen but not on general screen? This code moves window to center on general screen, not active screen:

import sys
from Py         


        
4条回答
  •  生来不讨喜
    2020-12-28 19:23

    One correction for PyQt5 users:

    import PyQt5
    
    def center(self):
        frameGm = self.frameGeometry()
        screen = PyQt5.QtWidgets.QApplication.desktop().screenNumber(PyQt5.QtWidgets.QApplication.desktop().cursor().pos())
        centerPoint = PyQt5.QtWidgets.QApplication.desktop().screenGeometry(screen).center()
        frameGm.moveCenter(centerPoint)
        self.move(frameGm.topLeft())
    

提交回复
热议问题