码迷,mamicode.com
首页 > 其他好文 > 详细

QHBoxLayout 、QFormLayout 遍历子部件,查找QLineEdit控件

时间:2019-08-20 22:30:39      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:ddr   you   index   ddl   str   编辑   empty   nbsp   text   

布局如下:

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控件

标签:ddr   you   index   ddl   str   编辑   empty   nbsp   text   

原文地址:https://www.cnblogs.com/azbane/p/11385760.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!