修改您的
center方法,如下所示:
def center(self): frameGm = self.frameGeometry() screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos()) centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center() frameGm.moveCenter(centerPoint) self.move(frameGm.topLeft())
此功能基于鼠标指针所在的位置。它使用screenNumber函数来确定鼠标当前在哪个屏幕上处于活动状态。然后,找到该监视器的screenGeometry和该屏幕的中心点。使用此方法,即使监视器分辨率不同,您也应该能够将窗口放置在屏幕中央。



