通过@ekhumoro的正确指示,我发现了以下作品(不正确!请参见下面的修订版。):
# Get the screen real estate available to the form
ag = QDesktopWidget().availableGeometry(form)
# If the saved values fall within that real estate,we can
# safely assign the values to the form's geometry
if ag.contains(QRect(x_pos,y_pos,h_dim,v_dim)):
form.setGeometry(x_pos,v_dim)
else:
# Otherwise,set it to default values that ARE available
form.setGeometry(ag.x(),ag.y(),v_dim)
QDesktopWidget对象与QApplication.desktop()对象相同,并且是从PyQt5.QtWidgets派生的。 QRect是从PyQt5.QtCore导入的
版本:
首先需要将表单的几何图形设置为保存的值,然后然后查看其是否在可用几何图形内。如果将表单保存在除主屏幕之外的任何位置,则每次如上所述的首先检查都会失败。
# Set the form to the saved position
form.setGeometry(x_pos,v_dim)
# Get the screen real estate available to the form
ag = QDesktopWidget().availableGeometry(form)
# If the saved values have placed the form within
# that real estate,we can leave it alone.
if not ag.contains(QRect(x_pos,v_dim)):
# Otherwise,set it to default values that ARE available
form.setGeometry(ag.x(),v_dim)
本文链接:https://www.f2er.com/3155698.html