2011-04-19 80 views

回答

1

首先,我会建议不要试图强迫用户一个窗口位置,并让系统的窗口管理器决定它应该去。如果你真的坚持自己的定位它(也许你正在编写一亭),你可以在计算器上一个问题找到some information here

这样做

稍微更优雅计算discussed here.

在做这样的计算,它是重要的,它是在正确的时间做,Qt拥有一切大小,只是它在屏幕上显示之前之后。一种可能有用的方法是create a one-shot timer并在定时器的插槽中进行屏幕定位。

+0

好地感谢阿诺德 – 2011-04-19 15:43:33

4

我知道你已经解决了这个问题,但我做这个答案对于那些谁拥有了同样的问题。我发布它主要是因为你要求pyQt而另一个答案是Qt(C++)。 我发现了一个解决方法在这里:https://bashelton.com/2009/06/pyqt-center-on-screen/

是如此简单和完美的作品,我传送吧..

class ExampleWindow (QtGui.QMainWindow): 
    def __init__ (self, parent=None): 
     '''constructor''' 
     QtGui.QMainWindow.__init__(self, parent) 
     self.setGeometry(0, 0, 650, 550) 
     self.setWindowTitle("My Example Application") 
     self.centerOnScreen() 

    def centerOnScreen (self): 
     '''centerOnScreen() 
Centers the window on the screen.''' 
     resolution = QtGui.QDesktopWidget().screenGeometry() 
     self.move((resolution.width()/2) - (self.frameSize().width()/2), 
        (resolution.height()/2) - (self.frameSize().height()/2)) 

祝你好运!