且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将所有项目设置为 PyQt5 的默认值(标签除外)的方法?

更新时间:2023-01-26 23:34:30

没有清除所有输入的方法.一个简单的解决方案是使用 findChildren 方法遍历小部件:

There is no method that cleans all the inputs. A simple solution is to iterate over the widgets using the findChildren method:

for widget in parent_widget.findChildren([QLineEdit, QComboBox]):
    if hasattr(widget, "clear") and callable(widget.clear):
        widget.clear()

for widget in parent_widget.findChildren(QWidget):
    if not isinstance(widget, QLabel) and hasattr(widget, "clear") and callable(widget.clear):
        widget.clear()