Pyside6 allWidgets()函数详细教程

PySide6.QtWidgets.QApplication类的成员函数allWidgets()用于返回一个包含所有小部件对象的列表;

示例代码

import sys
from PySide6.QtWidgets import QApplication,QWidget,QPushButton,QVBoxLayout
from PySide6.QtCore import Slot

class MyWidget(QWidget):
    def __init__(self):
        super().__init__()

        self.button = QPushButton("打印所有小部件")
        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.button)
        self.button.clicked.connect(self.printAllWidgets)

    @Slot()
    def printAllWidgets(self):
        for widget in app.allWidgets():#遍历返回的小部件对象列表
            print(widget)

app = QApplication([])
widget = MyWidget()
widget.resize(300, 200)
widget.show()
sys.exit(app.exec())

原创内容,如需转载,请注明出处;

本文地址: https://www.perfcode.com/p/pyside6-qtwidgets-qapplication-allwidgets.html

分类: 计算机技术
推荐阅读:
undefined reference to `WinMain' 解决方法 使用gcc对C代码进行编译时提示undefined reference to `WinMain',collect2.exe: error: ld returned 1 exit status;详细的信息大致如下:
Rust实现线性搜索算法(Linear Search) 本文将使用Rust实现线性搜索算法(Linear Search);
Rust解析YAML,结构体序列化和反序列化 serde_yaml 是 Rust 的一个 crate,提供了支持将数据结构序列化为 YAML 格式,以及将 YAML 格式反序列化为 Rust 数据结构的功能。
Golang中如何使用go test进行单元测试 单元测试的意义在这里就不多说了;本文将示范如何在Go语言环境下使用go test进行简单的单元测试。
C语言ispunct()函数:判断字符是否为标点符号 ispunct()是C语言标准库中的一个函数,用于检查一个字符是否为标点符号;如果传入的字符参数是标点符号,则返回非0值,否则返回0;
MySQL ADDDATE() 函数 ADDDATE()函数用于将一个时间值增加到一个日期当中;通俗的讲,就是可以通过这个函数将一个日期增加多少天;