Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • Seems progressBar and loggingArea are not the direct children of this?
    If their parent widget is disabled, they'll also be grey even if they are not disabled.



  • Seems progressBar and loggingArea are not the direct children of this?
    If their parent widget is disabled, they'll also be grey even if they are not disabled.



  • @Bonnie
    hmm they are printed out here for(auto *widget : this->findChildren<QWidget *>()) if I do qDebug() << widget->objectName();

    Would that not make them a direct child of this?

    Thanks,
    --James



  • @JSher

    QList<T> QObject::findChildren(const QString &name = QString(), Qt::FindChildOptions options = Qt::FindChildrenRecursively) const

    So the default option for findChildren is to find recursively. They might not be direct children.
    You are using ui, you should know that whether their parent widget is this or not?



  • @Bonnie

    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,:)



  • @Bonnie

    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



  • @JSher What is a loggingArea?
    If it is a scroll area, although itself is not disabled, but the viewport and scroll bars in it will be disabled.
    And any widget that has child widgets also have the same problem.



  • Ahh, basically its a terrible way to disable then, ill have to just do them all individually:)

    Thanks,
    --James


Log in to reply