Updating property of sibling when pseudo-element changes
-
Not sure if I'm using the right terminology, so bear with me.
I have a QCheckbox, and a QWidget (it can be a text, button, etc..) somewhere in my form.
I want to know if it's possible to set the QWidget'senabledstate, from the QCheckbox'scheckedpseudo-element.In C++ code this is what I mean
void on_QCheckbox_stateChanged(int checked) { if(checked == 2) ui->QWidget->setEnabled(true); else if(checked == 0) ui->QWidget->setEnabled(false); };Is this possible using only stylesheets?
-
Not sure if I'm using the right terminology, so bear with me.
I have a QCheckbox, and a QWidget (it can be a text, button, etc..) somewhere in my form.
I want to know if it's possible to set the QWidget'senabledstate, from the QCheckbox'scheckedpseudo-element.In C++ code this is what I mean
void on_QCheckbox_stateChanged(int checked) { if(checked == 2) ui->QWidget->setEnabled(true); else if(checked == 0) ui->QWidget->setEnabled(false); };Is this possible using only stylesheets?
@Josef-Lintz
No, because (even if it were possible to read some other widget's state in a different widget, which it is not) stylesheets can do nothing other than visual appearance, they cannot do any kind of "action", such as altering enablement state. -
I see so you can't change the
enabledstate, using a stylesheet. That's unfortunate.
Is there a way to change the visual appearance of sibling using another's pseudo-element?Similar to my C++ example, with a different property than
enabled, say,background-color? -
I see so you can't change the
enabledstate, using a stylesheet. That's unfortunate.
Is there a way to change the visual appearance of sibling using another's pseudo-element?Similar to my C++ example, with a different property than
enabled, say,background-color?@Josef-Lintz
Stylesheets really are only for changing the visual appearance of elements, nothing more. For example, they can alter how an enabled/disabled item looks, but not whether they are/are disabled.As I also wrote
(even if it were possible to read some other widget's state in a different widget, which it is not)
so, no, you cannot "change the visual appearance of sibling using another's pseudo-element".
-
As I also wrote
(even if it were possible to read some other widget's state in a different widget, which it is not)
Oh, apologies, I missed that.
That's very unfortunate. Thanks anyway. -
As I also wrote
(even if it were possible to read some other widget's state in a different widget, which it is not)
Oh, apologies, I missed that.
That's very unfortunate. Thanks anyway.@Josef-Lintz
Not that I have ever used QML, but I understand this is what its "property binding" system is good for. If you were using HTML + CSS, you would have to code this action in JavaScript. In Qt you must do it just the way you showed with a signal/slot action.