2016-08-19 37 views
0
def location_on_the_screen(self): 
    fg = self.frameGeometry() 
    sbrp = QDesktopWidget().availableGeometry().bottomRight() 
    fg.moveBottomRight(sbrp) 
    self.move(fg.topLeft()) 

私は画面の右下隅にウィンドウを置くことができません。 frameGeometry()は正常に動作しません。助けてください、どうしたらいいですか?PyQt - ウィンドウの位置

答えて

1

ここでは、Windows用の可能な解決策です:私が必要と

import sys 

from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget 


class MyWidget(QWidget): 

    def __init__(self): 
     super().__init__() 
     self.setFixedSize(400, 300) 

    def location_on_the_screen(self): 
     ag = QDesktopWidget().availableGeometry() 
     sg = QDesktopWidget().screenGeometry() 

     widget = self.geometry() 
     x = ag.width() - widget.width() 
     y = 2 * ag.height() - sg.height() - widget.height() 
     self.move(x, y) 

if __name__ == '__main__': 
    app = QApplication(sys.argv) 
    widget = MyWidget() 
    widget.location_on_the_screen() 
    widget.show() 
    app.exec_() 
0

あなたの 'ウィンドウ'はQWidgetのサブクラスであると仮定します。その場合は、次はあなたのニーズに合わせなければならない:

import sys 

from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget 


class MyWidget(QWidget): 

    def __init__(self): 
     super().__init__() 
     self.setFixedSize(400, 300) 

    def location_on_the_screen(self):  
     screen = QDesktopWidget().screenGeometry() 
     widget = self.geometry() 
     x = screen.width() - widget.width() 
     y = screen.height() - widget.height() 
     self.move(x, y) 


if __name__ == '__main__': 
    app = QApplication(sys.argv) 
    widget = MyWidget() 
    widget.location_on_the_screen() 
    widget.show() 
    app.exec_() 
+0

は、あなたの答えをありがとう、しかし、このコードも動作していません。 : http://i.imgur.com/YY0Y67D.png – Newbie

+0

私のコードと同じ問題です。http://i.imgur.com/QOQNEPB.png – Newbie

+0

MacOSとUbuntuで完全に動作します。Windows OSはありません。私はテストすることができないので、 'QDesktopWidget()。screenGeometry()'で考慮されていないスタートメニューバーの高さに問題があるようです。 –

関連する問題