main_layout.addLayout(right_layout)
时间: 2024-05-27 10:10:12 浏览: 63
这段代码是将right_layout添加到main_layout中。在Qt中,可以使用QHBoxLayout或QVBoxLayout来创建布局,然后将它们添加到另一个布局中。这样可以通过嵌套来实现复杂的布局。在这个例子中,right_layout被添加到main_layout中,可能是作为右侧的布局。
相关问题
def initUI(self): self.setWindowTitle(self.title) screen = QApplication.primaryScreen() size = screen.size() self.setGeometry((size.width() - self.width) // 2, (size.height() - self.height) // 2, self.width, self.height) # Prompt Label and Edit box prompt_label = QLabel('对象:', self) prompt_label.setStyleSheet('color: #222; font-size: 30px; margin-bottom: 10px; font-weight: bold;') self.prompt_edit = QTextEdit(self) self.prompt_edit.setStyleSheet('color: #333; font-size: 24px; border: 1px solid #ccc; padding: 5px;') prompt_layout = QHBoxLayout() prompt_layout.addWidget(prompt_label) prompt_layout.addWidget(self.prompt_edit) # Question Label and Edit box question_label = QLabel('问题:', self) question_label.setStyleSheet('color: #222; font-size: 30px; margin-bottom: 10px; font-weight: bold;') self.question_edit = QTextEdit(self) self.question_edit.setStyleSheet('color: #333; font-size: 24px; border: 1px solid #ccc; padding: 5px;') question_layout = QHBoxLayout() question_layout.addWidget(question_label) question_layout.addWidget(self.question_edit) liangge_layout_layout = QVBoxLayout() liangge_layout_layout.addLayout(prompt_layout) liangge_layout_layout.addLayout(question_layout) # Adding submit button to question layout self.submit_btn = QPushButton('发送', self) self.submit_btn.setFixedWidth(150) self.submit_btn.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) self.submit_btn.setStyleSheet('color: #fff; background-color: #20639b; border: none; font-size: 24px; padding: 10px; border-radius: 5px;') self.submit_btn.clicked.connect(self.on_submit) # Change layout of question and submit button using QHBoxLayout question_submit_layout = QHBoxLayout() question_submit_layout.addLayout(liangge_layout_layout) question_submit_layout.addWidget(self.submit_btn) # JSON response Label and Edit box json_response_label = QLabel('回复:', self) json_response_label.setStyleSheet('color: #222; font-size: 30px; margin-bottom: 10px; font-weight: bold;') self.json_response_edit = QTextEdit(self) self.json_response_edit.setStyleSheet('color: #333; font-size: 24px; border: 1px solid #ccc; padding: 5px;') json_response_layout = QHBoxLayout() json_response_layout.addWidget(json_response_label) json_response_layout.addWidget(self.json_response_edit) # Main layout main_layout = QVBoxLayout() main_layout.setSpacing(20) main_layout.addLayout(question_submit_layout) main_layout.addLayout(json_response_layout) main_layout.setContentsMargins(30, 30, 30, 30) self.setLayout(main_layout) self.show()如何让按钮文本内容竖着显示?
你可以使用QPushButton的setStyleSheet方法设置按钮的样式表,将文本旋转90度,例如:
```
self.submit_btn.setStyleSheet('color: #fff; background-color: #20639b; border: none; font-size: 24px; padding: 10px; border-radius: 5px; transform: rotate(90deg);')
```
这里使用了transform属性将文本旋转了90度。
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筛选结果并展示
你可以在数据展示页面添加一个QLineEdit和一个QPushButton,让用户输入员工ID并点击按钮进行筛选。
具体实现方法如下:
1. 在QueryResultWindow类的初始化函数中添加以下代码来创建QLineEdit和QPushButton:
```
self.id_line_edit = QLineEdit()
self.filter_button = QPushButton('筛选')
self.filter_button.clicked.connect(self.filter_result)
```
2. 在layout中添加这两个控件:
```
layout.addWidget(self.id_line_edit)
layout.addWidget(self.filter_button)
```
3. 添加filter_result函数来执行筛选操作:
```
def filter_result(self):
id = self.id_line_edit.text().strip()
if len(id) == 0:
QMessageBox.warning(self, '提示', '请输入员工ID')
return
db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset')
cursor = db.cursor()
db_sql = f"SELECT * FROM table_name WHERE id = '{id}'"
cursor.execute(db_sql)
result = cursor.fetchall()
db.close()
if len(result) == 0:
QMessageBox.information(self, "提示", "没有找到符合条件的记录")
return
self.table_widget.setRowCount(0)
for row_num, row_data in enumerate(result):
self.table_widget.insertRow(row_num)
for col_num, col_data in enumerate(row_data):
self.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data)))
```
注意替换db_sql中的table_name为你的表名。这个函数会从数据库中查询符合条件的记录并展示在表格中。
4. 修改show_query1_result函数,在最开始添加以下代码,用于展示所有记录:
```
db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset')
cursor = db.cursor()
db_sql = """SELECT * FROM table_name"""
cursor.execute(db_sql)
result = cursor.fetchall()
db.close()
if len(result) == 0:
QMessageBox.information(self, "提示", "今日无员工工资记录")
return
```
注意同样替换db_sql中的table_name为你的表名。这个代码块会在进入数据展示页面时展示所有记录。
通过以上修改,你就可以在数据展示页面添加筛选功能了。
阅读全文