I want to disable all but a selected set of widgets in my Qt application.
What I am trying to do is to iterate all children of mainWindow using findChildren
and disable all the resulting widgets except 'myTable' using setEnabled(false)
.
QList<QWidget *> allWidgets = mainWindow->findChildren<QWidget *>("");
QList<QWidget*>::iterator it;
for (it = allWidgets.begin(); it != allWidgets.end(); it++) {
if ((*it)->objectName() != "myTable") // here, objectName is not working!!
{
(*it)->setEnabled(false);
}
}
objectName()
inside the above if
statement is not working. What do I put there?
You could use the accessibleName
property. Set it for the widget you need, and then check it in your cycle with acessibleName()
function. It is an empty string by default, so it should be fairly easy to find your widget.
Another alternative is to disable all widgets, and then just enable the one you need directly:
for( QWidget * w : widgets )
{
w->setEnabled(false);
}
ui->myTable->setEnabled(true);
Or, finally, you can set the objectName
property with the setObjectName()
function, and use it as you do in your code.