将所有项目设置为 PyQt5 的默认值(标签除外)的方法? [英] Way to set all items to defaults of PyQt5 except labels?

查看:56
本文介绍了将所有项目设置为 PyQt5 的默认值(标签除外)的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个框架并向该框架添加了许多 pyqt5 项目.

I have created a frame and added many pyqt5 items to that frame.

添加表单后,我想将框架的所有项目清除为默认空白值.我可以通过 .clear() 方法设置单个项目来做到这一点.

After adding the form, I want to clear all the items of the frame to default blank values. I can do that by setting individual items by .clear() method.

有什么办法可以一次性清除框架或选项卡中的所有项目以清除(或默认)值?

Is there any way where I can clear all the items in a frame or tab to clear(or default) values at one go?

推荐答案

没有清除所有输入的方法.一个简单的解决方案是使用 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()

这篇关于将所有项目设置为 PyQt5 的默认值(标签除外)的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆