Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Moved] Set Graphic background SVG depending on conditional

    QML and Qt Quick
    2
    3
    1825
    Loading More Posts
    • 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.
    • A
      ad5xj last edited by

      I think I am going to ask a newbie question but here goes anyway.

      I have created a working graphical item using layered SVG images. However I would like to change the first (background) layer depending on a conditional value set as a property.

      Is there a way in Qt Quick to use QML for something like the C++ case statement where there is more than two values for the conditional. I.E. value 1 value 2 and value 3, etc. the condition ? operator seems to only give two choices (condition is true or false).

      Depending on the conditional value (1,2,3, etc.) I intend to select the appropriate background SVG source rather than creating a unique item for each different value only changing the background.

      Ken AD5XJ

      1 Reply Last reply Reply Quote 0
      • M
        mbrasser last edited by

        You can use switch statements in QML as well (though there is a bug related to this at the moment; see http://bugreports.qt.nokia.com/browse/QTBUG-17012 for details). You can also use if/else if type constructs -- BoomBlock.qml from the samegame demo shows an example of this:
        @
        Image {
        id: img
        source: {
        if(type == 0){
        "pics/redStone.png";
        } else if(type == 1) {
        "pics/blueStone.png";
        } else {
        "pics/greenStone.png";
        }
        }
        ...
        }
        @

        Regards,
        Michael

        1 Reply Last reply Reply Quote 0
        • A
          ad5xj last edited by

          Thanks - that works perfect!

          Ken AD5XJ

          1 Reply Last reply Reply Quote 0
          • First post
            Last post