PDA

View Full Version : How to get the child widgets from a Widget?



prykHetQuo
29th January 2009, 06:13
Qt version: 4.4.3:


Consider the code:



QWidget *scrollAreaWidgetContents;

// ...


// Used for the naming of the checkboxes
unsigned count= 1;


// Adds the checkboxes empty
for(unsigned j= 1; j<= 8; ++j)
{
QCheckBox *checkBox= new QCheckBox(scrollAreaWidgetContents);

++count;

checkBox->setObjectName(QString("checkBox_%1").arg(QString::number(count)));
checkBox->setGeometry(QRect(50* (j+ 1)+ 37, 20* i, 83, 20));
}

// ...


switch(runLevelsInfostring[0])
{
case '0':
scrollAreaWidgetContents.nextInFocusChain()->setCheckState(Qt::Checked);
}


I want to make the checkbox named "checkBox_1", to become << checkBox_1->setCheckState(Qt::Checked); >> How can I do that?

Thanks.

spirit
29th January 2009, 06:26
take a look at QObject::findChild (http://doc.trolltech.com/4.4/qobject.html#findChild), QObject::findChildren (http://doc.trolltech.com/4.4/qobject.html#findChildren)

prykHetQuo
29th January 2009, 13:26
Thanks for your answer.