is it possible to change the default behavior of a checkable QGroupBox?
-
wrote on 10 Mar 2020, 06:21 last edited by
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.
-
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.
wrote on 10 Mar 2020, 07:58 last edited by JonB 3 Oct 2020, 07:58@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 Championwrote on 10 Mar 2020, 20:17 last edited by mrjj 3 Oct 2020, 20:19
Hi
You can cheat a bit and just use the signal toggled()
https://doc.qt.io/qt-5/qgroupbox.html#toggledvoid MainWindow::on_groupBox_toggled(bool status) { auto List = ui->groupBox->findChildren<QLineEdit *>(); for (QLineEdit *line : List ) { line->setEnabled( ! status ); } }
Works ok if you tweak the start settings a bit.
3/3