PyQt - 窗口的位置

新手上路,请多包涵
def location_on_the_screen(self):
    fg = self.frameGeometry()
    sbrp = QDesktopWidget().availableGeometry().bottomRight()
    fg.moveBottomRight(sbrp)
    self.move(fg.topLeft())

我无法将窗口放在屏幕的右下角。 frameGeometry() 无法正常工作。请帮帮我,我该怎么办?

原文由 Newbie 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 743
2 个回答

这是适用于 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_()

原文由 BPL 发布,翻译遵循 CC BY-SA 3.0 许可协议

from PyQt5.QtWidgets import QMainWindow, QLabel
from PyQt5.QtWidgets import QGridLayout, QWidget, QDesktopWidget
#------------------------------
def center_window():
   qtRectangle = self.frameGeometry()
   centerPoint = QDesktopWidget().availableGeometry().center()
   qtRectangle.moveCenter(centerPoint)
   self.move(qtRectangle.topLeft())
   #---------------------------------
if __name__ == '__main__':
    app = QApplication(sys.argv)
    widget = MyWidget()
    widget.window_center():
    widget.show()
    app.exec_()

原文由 yardimci 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题