https://www.cnblogs.com/yeungchie/
PyQt5
| from PyQt5.QtWidgets import * |
| from PyQt5.QtCore import * |
| from PyQt5.QtGui import * |
PySide2
| from PySide2.QtWidgets import * |
| from PySide2.QtCore import * |
| from PySide2.QtGui import * |
顶部应用
QApplication
| app = QApplication([]) |
| app.setStyle(QStyleFactory.create('Fusion')) |
| app.exec_() |
部件
窗口标题
| wg.setWindowTitle('YEUNGCHIE') |
窗口尺寸
| wg.resize(300, 200) |
| wg.size() |
| wg.setMinimumSize(300, 200) |
| wg.setMaximumSize(300, 200) |
| wg.minimumSize() |
| wg.maximumSize() |
| wg.setFixedSize(300, 200) |
| wg.setFixedWidth(300) |
| wg.setFixedHeight(200) |
| wg.setMinimumWidth(300) |
| wg.setMaximumWidth(300) |
| wg.minimumWidth() |
| wg.maximumWidth() |
| wg.setMinimumHeight(200) |
| wg.setMaximumHeight(200) |
| wg.minimumHeight() |
| wg.maximumHeight() |
窗口位置
窗口置顶
| wg.setWindowFlags(Qt.WindowStaysOnTopHint) |
设置布局
| wg.setLayout(self.gridLayout) |
QLabel
文本
| label.setText('LABEL') |
| label.text() |
| label.setIndent() |
| label.setToolTip( 'Tips' ) |
| label.setAlignment( Qt.AlignCenter | Qt.AlignRight ) |
事件
| label.linkClicked.connect(function) |
| label.setText('<a href="https://baidu.com">Baidu</a>') |
| label.linkHovered.connect(function) |
QCheckBox
文本
| checkBox.setText( 'Enable' ) |
| checkBox.text() |
点击
| checkBox.setChecked(True) |
| checkBox.setChecked(False) |
| checkBox.isChecked() |
QLineEdit
文本
| lineEdit.setText( 'working dir' ) |
| lineEdit.text() |
提示词
| lineEdit.setPlaceholderText( '输入框内提示词' ) |
| lineEdit.setToolTip( '鼠标悬停提示词' ) |
QComboBox
添加选项
| comboBox.addItem('virtuoso') |
| comboBox.addItem('skipper') |
| comboBox.addItems('R0 R90 MX MY MYR90'.split(' ')) |
| comboBox.insertItem(5, 'MXR90') |
| comboBox.insertItems(2, ['R180', 'R270']) |
移除选项
选择选项
| comboBox.setCurrentText( 'virtuoso' ) |
| comboBox.currentText() |
| comboBox.setCurrentIndex() |
| comboBox.currentIndex() |
选项编辑
| comboBox.setItemText(0, 'Calibre') |
| pushButton = QPushButton() |
文本
| pushButton.setText( 'OK' ) |
| pushButton.text() |
事件
| pushButton.linkClicked.connect(function) |
布局
| formLayout = QFormLayout() |
标签对齐
| formLayout.setLabelAlignment( Qt.AlignCenter | Qt.AlignRight ) |
增加 row
| formLayout.addRow("标签1 Label", label) |
| formLayout.addRow("标签2 CheckBox", checkBox) |
QGridLayout
| gridLayout = QGridLayout() |
添加组件
| gridLayout.addWidget(label, 0, 0) |
| gridLayout.addWidget(checkBox , 0, 1) |
| gridLayout.addWidget(lineEdit , 0, 2, 3, 1) |
FAQ
启动失败可以打开 debug 模式
| export QT_DEBUG_PLUGINS=1 |
缺少 qt5dxcb 安装即可
| yum -y install qt5dxcb-plugin.x86_64 |
本文作者:YEUNGCHIE
本文链接:https://www.cnblogs.com/yeungchie/p/16219094.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
2020-05-03 [ Skill ] 计算两点距离