概述
#!python3
import os
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QAction, QTextBrowser, QTableWidget, QAbstractItemView, QTableWidgetItem,
QMessageBox, QHeaderView, QDesktopWidget,QApplication
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
# self.resize(800, 500)
self.init_window_size()
self.init_widgets()
self.lay_widgets()
# 初始化进度显示窗口
def init_window_size(self):
scale = 0.75
desktop = QApplication.desktop()
win_width = int(desktop.width() * scale)
win_height = int(desktop.height() * scale)
self.resize(win_width, win_height)
self.center()
pass
def center(self):
screen = QDesktopWidget().screenGeometry()
coord_x = int((screen.width() - self.geometry().width()) * 0.5)
coord_y = int((screen.height() - self.geometry().height()) * 0.5)
self.move(coord_x, coord_y)
pass
def init_menu_bar(self):
self.menu_bar = self.menuBar()
#
self.action_config = QAction('配置', self)
self.menu_bar.addAction(self.action_config)
#
def show_help_information():
message = "当前版本"
QMessageBox.information(self, '使用说明', message)
pass
self.help_infomation = QAction('关于', self)
self.menu_bar.addAction(self.help_infomation)
self.help_infomation.triggered.connect(show_help_information)
#
def init_widgets(self):
self.init_menu_bar()
self.init_text_browser_display()
self.init_progress_table()
def lay_widgets(self):
self.centralwidget = QtWidgets.QWidget()
#
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.addWidget(self.text_browser)
self.horizontalLayout.addWidget(self.progress_table)
self.horizontalLayout.setStretch(0, 3)
self.horizontalLayout.setStretch(1, 2)
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 1)
#
self.setCentralWidget(self.centralwidget)
pass
# def lay_widgets1(self):
# self.lay_text_browser()
# self.lay_progress_table()
def init_text_browser_display(self):
self.text_browser = QTextBrowser(self)
# self.text_browser.setGeometry(QtCore.QRect(10, 30, 780, 460))
def lay_text_browser(self):
self.text_browser.setGeometry(QtCore.QRect(10, 30, 490, 460))
def put_to_display(self, info):
self.text_browser.append(moment(1) + info + 'n')
self.cursor = self.text_browser.textCursor()
self.text_browser.moveCursor(self.cursor.End)
def init_progress_table(self):
self.progress_table = QTableWidget(self)
# 设置不可编辑,设置行选中
self.progress_table.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.progress_table.setSelectionBehavior(QAbstractItemView.SelectRows)
# 设置自动调整列宽
self.progress_table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
#
self.progress_table.setColumnCount(2)
self.progress_table.setHorizontalHeaderLabels(['地址', '进度'])
def lay_progress_table(self):
self.progress_table.setGeometry(QtCore.QRect(501, 30, 300, 460))
def stipulate_dev_ip(self, ip_list):
self.ip_list = ip_list
total_rows = len(self.ip_list)
self.progress_table.setRowCount(total_rows)
#
row = 0
for ip in self.ip_list:
adjust_res = ip
description = '_'.join(list(map(str, adjust_res)))
self.progress_table.setItem(row, 0, QTableWidgetItem(description))
self.progress_table.setItem(row, 1, QTableWidgetItem('0%'))
row += 1
self.progress_table.viewport().update()
pass
pass
def set_value(self, desc, progress):
items = self.progress_table.findItems(desc, QtCore.Qt.MatchExactly)
if items:
res_row = items[0].row()
self.progress_table.setItem(res_row, 1, QTableWidgetItem(progress))
pass
self.progress_table.viewport().update()
pass
def closeEvent(self, event):
"""
对MainWindow的函数closeEvent进行重构
退出软件时结束所有进程
:param event:
:return:
"""
reply = QMessageBox.question(self, '提示', '是否要退出程序?',
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No)
if reply == QMessageBox.Yes:
event.accept()
os._exit(0)
else:
event.ignore()
pass
pass
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())
最后
以上就是愤怒大碗为你收集整理的QMainWindow控件与窗口等比缩放的全部内容,希望文章能够帮你解决QMainWindow控件与窗口等比缩放所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复