QHBoxLayout QFormLayout 遍历子部件,查找QLineEdit控件
Posted azbane
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了QHBoxLayout QFormLayout 遍历子部件,查找QLineEdit控件相关的知识,希望对你有一定的参考价值。
布局如下: QLineEdit * edit1 = new QLineEdit; QLineEdit * edit2 = new QLineEdit; QLineEdit * edit3 = new QLineEdit; QLineEdit * edit4 = new QLineEdit; QFormLayout * formLayout1 = new QFormLayout; QFormLayout * formLayout2 = new QFormLayout; formLayout1->addRow(QStringLiteral("编辑1"), edit1); formLayout1->addRow(QStringLiteral("编辑2"), edit2); formLayout2->addRow(QStringLiteral("编辑3"), edit3); formLayout2->addRow(QStringLiteral("编辑4"), edit4); QHBoxLayout * hLayout = new QHBoxLayout; hLayout->addLayout(formLayout1); hLayout->addLayout(formLayout2); ... 遍历查找每一个布局,判断QLineEdit输入是否为空 foreach(auto formLayoutChild, hLayout->children()) QFormLayout * formLayout = qobject_cast<QFormLayout*>(formLayoutChild); if (formLayout != nullptr) int itemCount = formLayout->count(); for(int itemIndex = 0; itemIndex < itemCount; itemIndex++) QLayoutItem * item = formLayout->itemAt(itemIndex); QLineEdit * lineEdit = qobject_cast<QLineEdit*>(item->widget()); if (lineEdit != nullptr) if (lineEdit->text().isEmpty()) return false; return true;
以上是关于QHBoxLayout QFormLayout 遍历子部件,查找QLineEdit控件的主要内容,如果未能解决你的问题,请参考以下文章