如何列出qwidget中包含de objectname中特定字符串的所有子项? 例如,如果我有: "general_widget", with children: "label_name_1" "label__1" "label_name_2" "label_id_2" "label_name_3" "label_id_3" "label_name_4" "label_id
例如,如果我有:
"general_widget", with children: "label_name_1" "label__1" "label_name_2" "label_id_2" "label_name_3" "label_id_3" "label_name_4" "label_id_4"
我想获得包含“name”作为objectName一部分的所有子项的列表,以及包含所有包含“id”的子项的另一个列表.谢谢!
有这样一个简单的功能:QList<QWidget> widgets(QWidget * parent, QString search) { QRegularExpression exp(search); return parent->findChildren<QWidget>(exp); }
并给出一个QWidget *小部件,您可以这样调用它:
QList<QWidget> name_list = widgets(widget, "name"); QList<QWidget> id_list = widgets(widget, "id");