Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. In horizontol alignment field, the usage of ternary expression does not seem to work as expected
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 304 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Parthi
    wrote on last edited by Parthi
    #1

    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.

    JonBJ KroMignonK 2 Replies Last reply
    0
    • P Parthi

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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...?

      1 Reply Last reply
      0
      • P Parthi

        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.

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #3

        @Parthi I would change your ternary in something simplier:

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

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved