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. [Moved] Set Graphic background SVG depending on conditional

[Moved] Set Graphic background SVG depending on conditional

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.0k 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.
  • A Offline
    A Offline
    ad5xj
    wrote on last edited by
    #1

    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
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        ad5xj
        wrote on last edited by
        #3

        Thanks - that works perfect!

        Ken AD5XJ

        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