八月
24
QObject类型判定案例
import sys
from PySide2 import QtWidgets as qtw
app = qtw.QApplication()
window = qtw.QWidget()
label_1 = qtw.QLabel(window)
label_1.setText('安静一键宏')
label_2 = qtw.QLabel(window)
label_2.setText('轻松玩魔兽')
label_2.move(0, 30)
btn = qtw.QPushButton(window)
btn.setText('点我')
btn.move(0, 60)
# .children() 方法只是返回所有的子对象,没有findChildren的过滤功能
for item in window.children():
if item.inherits('QLabel'):
item.setStyleSheet('background-color: red;')
window.show()
sys.exit(app.exec_())