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()如何让按钮文本内容竖着显示?
时间: 2023-12-21 13:03:29 浏览: 30
你可以使用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度。
相关问题
self.setWindowTitle('员工登录系统')怎么居中显示
可以使用`QDesktopWidget`类来实现窗口居中显示。具体实现方法如下:
```python
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QDesktopWidget
class MyWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('员工登录系统')
self.resize(400, 300)
# 获取屏幕大小
screen = QDesktopWidget().screenGeometry()
# 获取窗口大小
size = self.geometry()
# 计算居中的位置
self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
```
在这段代码中,我们先使用`QDesktopWidget`类获取屏幕的大小,再使用`self.geometry()`方法获取窗口大小,最后计算出窗口居中的位置并调用`self.move()`方法将窗口移动到该位置即可。
class LoginWindow(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setFixedSize(800, 500) self.setWindowTitle('鸡爪称重系统') if __name__ == '__main__': app = QApplication(sys.argv) loginWindow = LoginWindow() loginWindow.show() sys.exit(app.exec_())创建一个按钮
可以在 `initUI` 方法中添加一个按钮,如下所示:
```python
class LoginWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setFixedSize(800, 500)
self.setWindowTitle('鸡爪称重系统')
# 创建一个按钮
button = QPushButton('点击我', self)
button.move(100, 100)
if __name__ == '__main__':
app = QApplication(sys.argv)
loginWindow = LoginWindow()
loginWindow.show()
sys.exit(app.exec_())
```
这样就在窗口中创建了一个名为“点击我”的按钮,并且该按钮的位置是 `(100, 100)`。