Disabling UI through children issue
-
Hello,
I have the code:
for(auto *widget : this->findChildren<QWidget *>()) { if((widget->objectName() != "progressBar") and (widget->objectName() != "loggingArea")){ widget->setEnabled(false); } }This still greys out the whole UI(I checked the names are correct.
Then I tried:
for(auto *widget : this->findChildren<QWidget *>()) { widget->setEnabled(false); } ui->progressBar->setEnabled(true); ui->loggingArea->setEnabled(true);This still has progressBar and loggingArea greyed.
This is in a button click method.
What am I doing wrong?
Thanks,
--James -
@Bonnie
hmm they are printed out herefor(auto *widget : this->findChildren<QWidget *>())if I doqDebug() << widget->objectName();Would that not make them a direct child of
this?Thanks,
--JamesQList<T> QObject::findChildren(const QString &name = QString(), Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
So the default option for
findChildrenis to find recursively. They might not be direct children.
You are using ui, you should know that whether their parent widget isthisor not? -
I am assuming it is grabbing the layout as well then and disabling it as well and that is why I cannot just enable that widget as its parent is disabled. Its built through the designer so I never looked TBH, was just looking for a fast way to disable all my widgets except 2.
Thanks,:)
-
I did more testing. if I do this:
if((widget->objectName() != "centralwidget") and (widget->objectName() != "loggingArea") ){ widget->setEnabled(false); }this still greys the whole UI.
Also:
ui->loggingArea->parent()->parent()->objectName()Is MainWindow which is
this.Any ideas?
Thanks,
--James -
I did more testing. if I do this:
if((widget->objectName() != "centralwidget") and (widget->objectName() != "loggingArea") ){ widget->setEnabled(false); }this still greys the whole UI.
Also:
ui->loggingArea->parent()->parent()->objectName()Is MainWindow which is
this.Any ideas?
Thanks,
--James