2011-04-19 114 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)) 

祝你好運!