I'd like to make widgets in some layout inaccessible, so a user would not be able to change a state of any layout's widgets (I want everything grayed out). I created a SIGNAL/SLOT, the method is called:
void MyWidget::slot( bool bChecked )
{
myLayout->setEnabled(bChecked);
std::cout << "OnAllToggled: " << bChecked <<
", isEnabled: " << myLayout->isEnabled() << std::endl;
}
everything is great except that the layout is still accessible. Apparently I don't understand the meaning of setEnabled method.
Question: what does setEnabled mean and how can I make the layout inaccessible? Thanks!
I'd like to make widgets in some layout inaccessible, so a user would not be able to change a state of any layout's widgets (I want everything grayed out).
And you try to disable the layout object. Of course, enabling or disabling layout affects the way widgets aligned against each other:
void QLayout::setEnabled(bool enable)
Enables this layout if enable is true, otherwise disables it.
An enabled layout adjusts dynamically to changes; a disabled layout acts as if it did not exist.
By default all layouts are enabled.
Instead you can attempt to disable all the children for some parent widget:
Disabling a widget implicitly disables all its children. Enabling respectively enables all child widgets unless they have been explicitly disabled. It it not possible to explicitly enable a child widget which is not a window while its parent widget remains disabled.
For that you can create some 'container' widget that occupies the layout you are talking about and add the nested layout to that widget to accommodate all the widgets.
QWidget* container = new QWidget;
myLayout->addWidget(container); // put container widget in myLayout
QHBoxLayout* hboxLayout = new QHBoxLayout(container);
hBoxLayout->addWidget(widget1);
hBoxLayout->addWidget(widget2);
hBoxLayout->addWidget(widget3);
container->setEnabled(false); // disable all nested widgets