我想将QMessageBox移动到屏幕的右下角,以下是我的代码,但效果不如预期,请问有谁能解释为什么?如何在这里解决问题?
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
def moveToBottomRight(msgBox):
msgBox.addButton("重计", QMessageBox.ActionRole)
msgBox.addButton("停计", QMessageBox.ActionRole)
msgBox.addButton('继续', QMessageBox.ActionRole)
screenGeometry = QApplication.desktop().availableGeometry()
screenGeo = screenGeometry.bottomRight()
msgGeo = msgBox.frameGeometry()
msgGeo.moveBottomRight(screenGeo)
msgBox.move(msgGeo.topLeft())
def main():
app = QApplication(sys.argv)
msgBox = QMessageBox()
moveToBottomRight(msgBox)
msgBox.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
msgBox
之前,它的框架(大小)未被定义,因此您正在使用无效的值进行计算。 - Marek RmsgBox.ensurePolished();
,@iMath是否能正常工作? - thuga