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()怎么设置按钮位置为两列
时间: 2024-02-01 14:15:48 浏览: 139
code-qt.rar_QT ProgressBar_QT button_qt layout_qt menu
要将按钮布局设置为两列,可以使用QGridLayout而不是QVBoxLayout。可以使用addWidget()方法将按钮添加到布局中,并指定它们的位置。以下是示例代码:
```
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) # 添加空白列来填充布局
layout = QHBoxLayout()
layout.addLayout(button_layout)
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
```
在上面的代码中,`button_layout`是一个QGridLayout,使用addWidget()方法来添加按钮到布局中,并指定它们的行和列。`setColumnStretch()`方法用于添加一个空白列来填充布局,使其呈现为两列。
阅读全文