赞
踩
- def auto_resize(self):
- # 获取窗口原来大小
- window_width = self.width()
- window_height = self.height()
- # 获取屏幕大小
- screen = QDesktopWidget().screenGeometry()
- screen_width = screen.width()
- screen_height = screen.height()
- # 自定义新窗口大小
- new_window_width = int(screen_width * 0.7)
- resize_rate = new_window_width / window_width # 确定放大比例
- new_window_height = int(window_height * resize_rate) # 确定新窗口高度
- # 重新调整窗口大小并移动到屏幕中心
- self.resize(new_window_width, new_window_height)
- self.move((screen_width - new_window_width) // 2, (screen_height - new_window_height) // 3)
- # 重新调整子控件位置大小
- for widget in self.findChildren(QWidget):
- rect = widget.geometry()
- widget.setGeometry(QRect(
- int(rect.x() * resize_rate),
- int(rect.y() * resize_rate),
- int(rect.width() * resize_rate),
- int(rect.height() * resize_rate),
- ))
- class Window(QMainWindow):
-
- def __init__(self):
- super().__init__()
- self.setupUi()
- self.auto_resize()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。