Pyside ---- Qt official python api
文章目录
环境配置错误
- 参考:PySide6开发环境 - 代码先锋网
设置环境变量
QT_QPA_PLATFORM_PLUGIN_PATH- 值:
D:\soft\miniconda3\envs\py38\Lib\site-packages\PySide6\plugins\platforms
- 值:
设置 QObject 属性
动态属性
setter & getter
- obj.setProperty("propName", "value")
- obj.property("propName")
遍历
- obj.dynamicPropertyNames()
| |
使用 CSS
方法
- QObject.setStyleSheet("css string")
定位
QObject.setObjectName
- css id selector: "QLabel#objectName"
eg:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37import sys from PySide6.QtWidgets import ( QWidget, QLabel, QApplication ) class Window(QWidget): def __init__(self): super().__init__() # 设置 CSS QApplication.instance().setStyleSheet("QLabel#yoyoyo {font-size: 20px; color: green; font-weight: bold;}") self.init_ui() def init_ui(self): self.setGeometry(400, 400, 300, 200) self.setWindowTitle("Summer Festival") label1 = QLabel(self) # Set name, QObject has properties, child controls can use # CSS 定位 label1.setObjectName("yoyoyo") label1.setText("Shasha") label1.move(50, 50) label2 = QLabel(self) # Do not set name label2.setText("Respiratory World") label2.move(50, 100) app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_())
子 Widget 遍历
QObject.children()
- 遍历直属 子 Widget
QObject.findChildren(QObject)
- 遍历所有 QObject
阻塞 Signal 传递
操作
- obj.mySignal.blockSignals(True)
判断
- obj.mySignal.signalIsBlocked()
signals
- obj.objectNameChanged
- obj.destroyed
- button.clicked
类型判断
- obj.isWidgetType()
layout 布局
注意
- layout::addWidget() 是正确做法
layout::addChildrenWidget()
- protected 方法,调用是错误的
删除
- obj.deleteLater()
信号 signal
- obj.destroyed
- obj.
文章作者
上次更新 2022-03-03 (5c64003)