button_layout = QVBoxLayout() button1 = QPushButton('当日员工工资') button1.clicked.connect(self.show_query1_result) button2 = QPushButton('当日鸡爪领取记录') button2.clicked.connect(self.show_query2_result) button3 = QPushButton('查询历史员工工资') button3.clicked.connect(self.show_query3_result) button4 = QPushButton('查询历史鸡爪领取记录') button4.clicked.connect(self.show_query4_result) button_layout.addWidget(button1) button_layout.addWidget(button2) button_layout.addWidget(button3) button_layout.addWidget(button4)怎么更改这4个按钮的大小

时间: 2023-07-16 19:15:22 浏览: 47
要更改这4个按钮的大小,可以使用setFixedSize函数,例如: ``` button1.setFixedSize(200, 50) button2.setFixedSize(200, 50) button3.setFixedSize(200, 50) button4.setFixedSize(200, 50) ``` 这将把所有四个按钮的大小设置为宽度为200像素,高度为50像素。您可以根据需要更改这些值。
相关问题

button_layout = QVBoxLayout() button1 = QPushButton('当日员工工资') button1.setFixedSize(200, 50) button1.clicked.connect(self.show_query1_result) button2 = QPushButton('当日鸡爪领取记录') button2.setFixedSize(200, 50) button2.clicked.connect(self.show_query2_result) button3 = QPushButton('查询历史员工工资') button3.setFixedSize(200, 50) button3.clicked.connect(self.show_query3_result) button4 = QPushButton('查询历史鸡爪领取记录') button4.setFixedSize(200, 50) button4.clicked.connect(self.show_query4_result) button_layout.addWidget(button1) button_layout.addWidget(button2) button_layout.addWidget(button3) button_layout.addWidget(button4)怎么把这4个按钮居中排列

可以使用QHBoxLayout来包装QVBoxLayout和四个按钮,然后设置该水平布局的对齐方式为居中对齐。以下是示例代码: ``` button_layout = QVBoxLayout() button_h_layout = QHBoxLayout() button1 = QPushButton('当日员工工资') button1.setFixedSize(200, 50) button1.clicked.connect(self.show_query1_result) button2 = QPushButton('当日鸡爪领取记录') button2.setFixedSize(200, 50) button2.clicked.connect(self.show_query2_result) button3 = QPushButton('查询历史员工工资') button3.setFixedSize(200, 50) button3.clicked.connect(self.show_query3_result) button4 = QPushButton('查询历史鸡爪领取记录') button4.setFixedSize(200, 50) button4.clicked.connect(self.show_query4_result) button_h_layout.addWidget(button1) button_h_layout.addWidget(button2) button_h_layout.addWidget(button3) button_h_layout.addWidget(button4) button_layout.addLayout(button_h_layout) button_layout.setAlignment(Qt.AlignCenter) ``` 这样,四个按钮就会在布局中居中排列。

button_layout = QHBoxLayout() button1 = QPushButton('当日员工工资') button1.clicked.connect(self.show_query1_result) button2 = QPushButton('当日鸡爪领取记录') button2.clicked.connect(self.show_query2_result) button3 = QPushButton('查询历史员工工资') button3.clicked.connect(self.show_query3_result) button4 = QPushButton('查询历史鸡爪领取记录') button4.clicked.connect(self.show_query4_result) button_layout.addWidget(button1) button_layout.addWidget(button2) button_layout.addWidget(button3) button_layout.addWidget(button4)怎么把这4个按钮改为竖向排列

可以使用QVBoxLayout代替QHBoxLayout,具体代码如下: ``` button_layout = QVBoxLayout() button1 = QPushButton('当日员工工资') button1.clicked.connect(self.show_query1_result) button2 = QPushButton('当日鸡爪领取记录') button2.clicked.connect(self.show_query2_result) button3 = QPushButton('查询历史员工工资') button3.clicked.connect(self.show_query3_result) button4 = QPushButton('查询历史鸡爪领取记录') button4.clicked.connect(self.show_query4_result) button_layout.addWidget(button1) button_layout.addWidget(button2) button_layout.addWidget(button3) button_layout.addWidget(button4) ``` 这样就可以实现垂直排列了。

相关推荐

button_layout = QVBoxLayout() button1 = QPushButton('当日员工工资') button1.setFixedSize(200, 50) button1.setStyleSheet('QPushButton {background-color: #A3C1DA; color: black; font-weight: bold;}') button1.clicked.connect(self.show_query1_result) button2 = QPushButton('当日鸡爪领取记录') button2.setFixedSize(200, 50) button2.setStyleSheet('QPushButton {background-color: #A3C1DA; color: black; font-weight: bold;}') button2.clicked.connect(self.show_query2_result) button3 = QPushButton('查询历史员工工资') button3.setFixedSize(200, 50) button3.setStyleSheet('QPushButton {background-color: #A3C1DA; color: black; font-weight: bold;}') button3.clicked.connect(self.show_query3_result) button4 = QPushButton('查询历史鸡爪领取记录') button4.setFixedSize(200, 50) button4.setStyleSheet('QPushButton {background-color: #A3C1DA; color: black; font-weight: bold;}') button4.clicked.connect(self.show_query4_result) button5 = QPushButton('按员工ID查询员工工资') button5.setFixedSize(200, 50) button5.setStyleSheet('QPushButton {background-color: #A3C1DA; color: black; font-weight: bold;}') button5.clicked.connect(self.show_query5_result) button6 = QPushButton('按员工ID查询鸡爪领取记录') button6.setFixedSize(200, 50) button6.setStyleSheet('QPushButton {background-color: #A3C1DA; color: black; font-weight: bold;}') button6.clicked.connect(self.show_query6_result) button_layout.addStretch() button_layout.addWidget(button1) button_layout.addWidget(button2) button_layout.addWidget(button3) button_layout.addWidget(button4) button_layout.addWidget(button5) button_layout.addWidget(button6) button_layout.addStretch() layout = QHBoxLayout() layout.addStretch() layout.addLayout(button_layout) layout.addStretch() widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) # 将按钮布局添加到主窗口布局中 main_layout.addLayout(button_layout) # 创建两个窗口用于展示查询结果 self.query1_window = QueryResultWindow() self.query2_window = QueryResultWindow() self.query3_window = QueryResultWindow() self.query4_window = QueryResultWindow() self.query5_window = QueryResultWindow() self.query6_window = QueryResultWindow()怎么设置按钮位置为两列

class MainWindow(QMainWindow): def init(self): super().init() # 设置主窗口大小 self.setFixedSize(800, 600) # 创建主窗口布局 main_layout = QVBoxLayout() central_widget = QWidget() central_widget.setLayout(main_layout) self.setCentralWidget(central_widget) # 创建两个竖向按钮 button_layout = QVBoxLayout() button1 = QPushButton('当日员工工资') button1.setFixedSize(200, 50) button1.clicked.connect(self.show_query1_result) button2 = QPushButton('当日鸡爪领取记录') button2.setFixedSize(200, 50) button2.clicked.connect(self.show_query2_result) button3 = QPushButton('查询历史员工工资') button3.setFixedSize(200, 50) button3.clicked.connect(self.show_query3_result) button4 = QPushButton('查询历史鸡爪领取记录') button4.setFixedSize(200, 50) button4.clicked.connect(self.show_query4_result) button_layout.addStretch() button_layout.addWidget(button1) button_layout.addWidget(button2) button_layout.addWidget(button3) button_layout.addWidget(button4) button_layout.addStretch() layout = QHBoxLayout() layout.addStretch() layout.addLayout(button_layout) layout.addStretch() widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) # 将按钮布局添加到主窗口布局中 main_layout.addLayout(button_layout) # 创建两个窗口用于展示查询结果 self.query1_window = QueryResultWindow() self.query2_window = QueryResultWindow() self.query3_window = QueryResultWindow() self.query4_window = QueryResultWindow() def show_query1_result(self): # 查询数据 db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """ """ cursor.execute(db_sql) result = cursor.fetchall() db.close() if len(result) == 0: QMessageBox.information(self, "提示", "今日无员工工资记录") return # 清空表格 self.query1_window.table_widget.setRowCount(0) self.query1_window.table_widget.setColumnCount(len(result[0])) self.query1_window.table_widget.setHorizontalHeaderLabels \ (["员工ID", "员工姓名", "日期", "领取鸡爪重量(KG)", "效率(每小时KG)", "出成率", "基础工资", "重量奖励", "当日总工资"]) # 添加数据到表格 for row_num, row_data in enumerate(result): self.query1_window.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) # 显示窗口 self.query1_window.show()数据展示页面怎么设置筛选器按ID筛选结果并展示

class MainWindow(QMainWindow): def init(self): super().init() self.setFixedSize(800, 600) main_layout = QVBoxLayout() central_widget = QWidget() central_widget.setLayout(main_layout) self.setCentralWidget(central_widget) button_layout = QVBoxLayout() button1 = QPushButton('当日员工工资') button1.setFixedSize(200, 50) button1.clicked.connect(self.show_query1_result) button_layout.addStretch() button_layout.addWidget(button1) button_layout.addStretch() layout = QHBoxLayout() layout.addStretch() layout.addLayout(button_layout) layout.addStretch() widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) main_layout.addLayout(button_layout) self.query1_window = QueryResultWindow() def show_query1_result(self): db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """ """ cursor.execute(db_sql) result = cursor.fetchall() db.close() if len(result) == 0: QMessageBox.information(self, "提示", "今日无员工工资记录") return self.query1_window.table_widget.setRowCount(0) self.query1_window.table_widget.setColumnCount(len(result[0])) self.query1_window.table_widget.setHorizontalHeaderLabels( ["员工ID", "员工姓名", "日期", "领取鸡爪重量(KG)", "效率(每小时KG)", "出成率", "基础工资", "重量奖励", "当日总工资"]) for row_num, row_data in enumerate(result): self.query1_window.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) self.query1_window.show() class QueryResultWindow(QWidget): def init(self): super().init() self.setFixedSize(800, 600) self.table_widget = QTableWidget() self.table_widget.setEditTriggers(QTableWidget.NoEditTriggers) self.table_widget.setSelectionBehavior(QTableWidget.SelectRows) layout = QVBoxLayout() layout.addWidget(self.table_widget) self.setLayout(layout) if name == 'main': app = QApplication(sys.argv) loginWindow = LoginWindow() loginWindow.show() sys.exit(app.exec_()))数据展示页面怎么设置筛选器按ID筛选结果并展示的整体代码

button_layout = QGridLayout() button1 = QPushButton('当日员工工资') button1.setFixedSize(200, 50) button1.setStyleSheet('QPushButton {background-color: #A3C1DA; color: black; font-weight: bold;}') button1.clicked.connect(self.show_query1_result) button_layout.addWidget(button1, 0, 0) button2 = QPushButton('当日鸡爪领取记录') button2.setFixedSize(200, 50) button2.setStyleSheet('QPushButton {background-color: #A3C1DA; color: black; font-weight: bold;}') button2.clicked.connect(self.show_query2_result) button_layout.addWidget(button2, 0, 1) button3 = QPushButton('查询历史员工工资') button3.setFixedSize(200, 50) button3.setStyleSheet('QPushButton {background-color: #A3C1DA; color: black; font-weight: bold;}') button3.clicked.connect(self.show_query3_result) button_layout.addWidget(button3, 1, 0) button4 = QPushButton('查询历史鸡爪领取记录') button4.setFixedSize(200, 50) button4.setStyleSheet('QPushButton {background-color: #A3C1DA; color: black; font-weight: bold;}') button4.clicked.connect(self.show_query4_result) button_layout.addWidget(button4, 1, 1) button5 = QPushButton('按员工ID查询员工工资') button5.setFixedSize(200, 50) button5.setStyleSheet('QPushButton {background-color: #A3C1DA; color: black; font-weight: bold;}') button5.clicked.connect(self.show_query5_result) button_layout.addWidget(button5, 2, 0) button6 = QPushButton('按员工ID查询鸡爪领取记录') button6.setFixedSize(200, 50) button6.setStyleSheet('QPushButton {background-color: #A3C1DA; color: black; font-weight: bold;}') button6.clicked.connect(self.show_query6_result) button_layout.addWidget(button6, 2, 1) button_layout.setColumnStretch(2, 1) # 添加空白列来填充布局 v_layout = QVBoxLayout() v_layout.addStretch() # 添加弹性空间,使按钮布局垂直居中 v_layout.addLayout(button_layout) v_layout.addStretch(),其中self.setStyleSheet( """ QPushButton { background-color: #A3C1DA; color: black; font-weight: bold; border-radius: 5px; border: 2px solid #555555; padding: 5px; } QPushButton:hover { background-color: #C9E2F3; color: #555555; } """ )该加在什么地方

def query(self,sql): # 执行 SQL 查询语句 self.cursor.execute(sql) # 创建一个新窗口,并设置其属性 new_window = QWidget(self) new_window.setWindowTitle("查询员工信息") new_window.setGeometry(200, 200, 400, 300) # 创建返回按钮并设置其属性 return_button = QPushButton("返回", new_window) return_button.setGeometry(200, 200, 400, 300) return_button.clicked.connect(new_window.close) # 获取查询结果并显示在表格中 rows = self.cursor.fetchall() self.table = QTableWidget() if rows: self.table.setRowCount(len(rows)) self.table.setColumnCount(len(rows[0])) for i, row in enumerate(rows): for j, col in enumerate(row): item = QTableWidgetItem(str(col)) self.table.setItem(i, j, item) self.table.setHorizontalHeaderLabels(["部门", "姓名", "性别", '职位', '工号', '状态']) self.table.horizontalHeader().setVisible(True) self.input_box = QLineEdit(new_window) self.status_label.setText("输入需要查询的数据,格式为:部门/姓名/性别/职位/工号/状态,对象") self.v_layout = QVBoxLayout(new_window) self.v_layout.addWidget(self.input_box) query_button = QPushButton("单个查询", new_window) query_button.setGeometry(300, 100, 50, 30) query_button.clicked.connect(lambda: self.query_data(new_window)) # 添加表格到新窗口中 self.v_layout.addWidget(self.table) new_window.setLayout(self.v_layout) new_window.show() def query_data(self, new_window): # 获取输入框中的数据 data = self.input_box.text().split(",") if len(data) != 2 or not all(map(lambda x: x.strip(), data)): self.status_label.setText("输入格式错误!请按照 部门/姓名/性别/职位/工号/状态,对象 格式输入。") return # 检查是否有存在的表 if self.table: self.v_layout.removeWidget(self.table) self.table = None # 执行 SQL 查询语句 sql = "select * from Staff where {} = (?)".format(data[0]) self.cursor.execute(sql, (data[1],)) # 获取查询结果并显示在表格中 rows = self.cursor.fetchall() self.table = QTableWidget() if rows: self.table.setRowCount(len(rows)) self.table.setColumnCount(len(rows[0])) for i, row in enumerate(rows): for j, col in enumerate(row): item = QTableWidgetItem(str(col)) self.table.setItem(i, j, item) self.table.setHorizontalHeaderLabels(["部门", "姓名", "性别", '职位', '工号', '状态']) self.table.horizontalHeader().setVisible(True) # 添加表格到新窗口中 self.v_layout = QVBoxLayout(new_window) self.v_layout.addWidget(self.table) new_window.setLayout(self.v_layout) new_window.show()改错中文

def delete_data(self): # 创建一个新窗口,并设置其属性 status_label = QLabel() new_window = QWidget(self) new_window.setWindowTitle("删除员工信息") new_window.setGeometry(200, 200, 500, 300) # 创建返回按钮并设置其属性 return_button = QPushButton("返回", new_window) return_button.clicked.connect(new_window.close) return_button.clicked.connect(self.window.show) # 设置输入框 self.input_box = QLineEdit(new_window) status_label.setText("输入需要删除的对象,格式为:部门/姓名/性别/职位/工号/状态,对象") # 设置删除按钮 delete_button = QPushButton("删除",new_window) delete_button.clicked.connect(self.delete) # 添加表格、按键到新窗口中 self.v_layout = QVBoxLayout(new_window) self.v_layout.addWidget(status_label) self.v_layout.addWidget(self.input_box) self.v_layout.addWidget(return_button) self.v_layout.addWidget(status_label) new_window.setLayout(self.v_layout) new_window.show() def delete(self): # 获取输入框中的数据 data = self.input_box.text().split(",") if len(data) != 2 or not all(map(lambda x: x.strip(), data)): self.status_label.setText("输入格式错误!请按照 部门/姓名/性别/职位/工号/状态,对象 的格式输入。") return # 执行 SQL 删除语句 sql = "DELETE FROM Staff WHERE {} = (?)".format(data[0]) self.cursor.execute(sql, (data[1],)) try: self.cursor.execute(sql, data[0]) self.cnxn.commit() self.query("SELECT * FROM Staff") self.status_label.setText("数据删除成功!") except: self.status_label.setText("数据删除失败!")查错

最新推荐

recommend-type

rockyou.txt

rockyou
recommend-type

ASP+ACCESS网上人才信息管理系统(源代码+论文)【ASP】.zip

ASP+ACCESS网上人才信息管理系统(源代码+论文)【ASP】
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB结构体与对象编程:构建面向对象的应用程序,提升代码可维护性和可扩展性

![MATLAB结构体与对象编程:构建面向对象的应用程序,提升代码可维护性和可扩展性](https://picx.zhimg.com/80/v2-8132d9acfebe1c248865e24dc5445720_1440w.webp?source=1def8aca) # 1. MATLAB结构体基础** MATLAB结构体是一种数据结构,用于存储和组织相关数据。它由一系列域组成,每个域都有一个名称和一个值。结构体提供了对数据的灵活访问和管理,使其成为组织和处理复杂数据集的理想选择。 MATLAB中创建结构体非常简单,使用struct函数即可。例如: ```matlab myStruct
recommend-type

详细描述一下STM32F103C8T6怎么与DHT11连接

STM32F103C8T6可以通过单总线协议与DHT11连接。连接步骤如下: 1. 将DHT11的VCC引脚连接到STM32F103C8T6的5V电源引脚; 2. 将DHT11的GND引脚连接到STM32F103C8T6的GND引脚; 3. 将DHT11的DATA引脚连接到STM32F103C8T6的GPIO引脚,可以选择任一GPIO引脚,需要在程序中配置; 4. 在程序中初始化GPIO引脚,将其设为输出模式,并输出高电平,持续至少18ms,以激活DHT11; 5. 将GPIO引脚设为输入模式,等待DHT11响应,DHT11会先输出一个80us的低电平,然后输出一个80us的高电平,
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

MATLAB结构体与数据库交互:无缝连接数据存储与处理,实现数据管理自动化

![MATLAB结构体与数据库交互:无缝连接数据存储与处理,实现数据管理自动化](https://ww2.mathworks.cn/products/database/_jcr_content/mainParsys/band_1749659463_copy/mainParsys/columns_copy/6d5289a2-72ce-42a8-a475-d130cbebee2e/image_copy_2009912310.adapt.full.medium.jpg/1709291769739.jpg) # 1. MATLAB结构体与数据库交互概述** MATLAB结构体与数据库交互是一种强大的
recommend-type

Link your Unity

project to C# script in Visual Studio. Can you provide me with some guidance on this? Yes, I can definitely help you with that! To link your Unity project to C# script in Visual Studio, you first need to make sure that you have both Unity and Visual Studio installed on your computer. Then, you can