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

is it possible to change the default behavior of a checkable QGroupBox?



  • The question is pretty straight forward: is it possible to change the default behavior of a checkable QGroupBox object? I designed a user interface with many QLineEdit objects inside a checkable QGroupBox, the desired behavior is: when QGroupBox is not checked all of its children are enable and when it is checked all of its children are disable.

    As you can see at the oficial QGroupBox documentation, it says:

    If the check box is checked, the group box's children are enabled; otherwise, the children are disabled and are inaccessible to the user.



  • @Savio-Brilhante
    I don't see that you can alter the default behaviour. However, you may be able to subclass and provide your own reversed behaviour for child enablement.


  • Lifetime Qt Champion

    Hi
    You can cheat a bit and just use the signal toggled()
    https://doc.qt.io/qt-5/qgroupbox.html#toggled

    void MainWindow::on_groupBox_toggled(bool status)
    {
        auto List = ui->groupBox->findChildren<QLineEdit *>();
        for (QLineEdit *line : List ) {
            line->setEnabled( ! status );
        }
    
    }
    
    

    alt text

    Works ok if you tweak the start settings a bit.


Log in to reply