OK, I think QML should have a special syntax then. For example,

TextField {
    font.family: text.contains("test") ? "Inter" : *untouched*
}

So, I do not then want for QML to even keep a default value somewhere. All
I would like is for it to be able to just not change property value except
the specified case.

I think it should be possible to easily implement such a feature inside of
a QML engine.

QML meets a special "untouched" word as a property value? It just does
nothing then. Should be easy :)

On Sun, Oct 13, 2024 at 2:26 AM Mike Trahearn <
miketrahe...@codeceptsoftware.com> wrote:

> The topic of "conditional bindings" of this format has has extensive
> coverage in another mailing list thread which contains examples and
> explanations for all possible outcomes for different scenarios.
> The long and short is - making your expression doing exactly what you want
> whenever the result of the expression changes - in both directions or you
> risk it getting "stuck".
> If you want to reset to a known default value when false, then there are
> multiple ways to do this. However there isn't a simple syntax that says so
> something only when... xyx in the ternary form as you presented since the
> expression in such a form must produce a valid result - even if it is
> undefined and the property concerned has a RESET function in its C++
> definition. For your own QML properties you can't define a reset function
> purely in QML so you must provide a valid result for both the true and
> false case. Have a search in the mailing list first lest I get caught out
> repeating what has already been very well covered by others and I hope it
> helps you get where you need without too much trouble.
>
> On Sat, 12 Oct 2024, 5:27 pm Alexander Dyagilev, <alervd...@gmail.com>
> wrote:
>
>> Hello,
>>
>> As example, let's suppose I would like to change font name for a
>> TextField only in case it contains "test" text.
>>
>> What is the best way to do it in QML? Is there any special syntax maybe?
>>
>> TextField {
>>     font.family: text.contains("test") ? "Inter" : DONT_CHANGE_PROPERTY
>> }
>> _______________________________________________
>> Interest mailing list
>> Interest@qt-project.org
>> https://lists.qt-project.org/listinfo/interest
>>
>
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to