QWidget *widget;
QLineEdit *text;
widget->addWidget(text);
widget->setEnabled(false);
qDebug()<<widget->isEnabled(); // false
qDebug()<<text->isEnabled(); //true
In a QWidget, there are multiple child widgets, including QLabel and QTextEdit.
Now I want to change the style in QSS based on the QWidget’s enabled value.
For example:
QTextEdit:enabled { background-color: lime; }
QTextEdit:disabled { background-color: red; }
However, this approach doesn’t seem to work. Later, I realized that changing the enabled property of the parent widget (QWidget) doesn’t automatically affect the same-named property of its child widgets.
But in practice, I indeed cannot manipulate the child widgets anymore.
What could be the reason for this behavior? Besides writing slot functions and conditional logic, is there any other way to achieve synchronization of the same-named properties between parent and child components?
Adam4Ram3 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.