Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

In horizontol alignment field, the usage of ternary expression does not seem to work as expected



  • horizontalAlignment: ((variable) ?
    (!variable1 && variable2 ? Text.AlignRight : Text.AlignHCenter):
    (!variable1 && variable2 ? Text.AlignLeft : Text.AlignHCenter))

    In the above statement, the horizontol alignment does not align the text to right instead aligns to left, when variable is true and variable1 is false and variable2 is true. But when the Text.AlignRight is directly assigned to horizontalAlignment field, the text gets aligned to right. The above issue is seen when the language is changed to Arabic.



  • @Parthi
    Your expression precedence looks right to me. For the one in a million chance there's a precedence issue, in your second & third lines put in parentheses like:

    horizontalAlignment: ((variable) ?
    ( (!variable1 && variable2) ? Text.AlignRight : Text.AlignHCenter):
    ( (!variable1 && variable2) ? Text.AlignLeft : Text.AlignHCenter))
    

    just in case...? Or, move the (!variable1 && variable2) into a variable and use that? Try with a variable/debug statement instead of assigning to horizontalAlignment? Else report as a bug...?



  • @Parthi I would change your ternary in something simplier:

    horizontalAlignment: (variable1 || !variable2 ? Text.AlignHCenter : (variable ? Text.AlignRight : Text.AlignLeft))
    

Log in to reply