Qt Forum

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

    [SOLVED][JS] id in parameter

    QML and Qt Quick
    3
    10
    2335
    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.
    • F
      fmontigny last edited by

      Hi,

      I have main.qml.
      @import Qt 4.7

      Item {
      id: topMiddlePane

      Image {
          id: buttonClasse
          source: "pict/button1Off.png"
          x: 329
          y: 0
           width: 123
           height: 52
          opacity: 1
      
          MouseArea {
              anchors.fill: parent
              hoverEnabled: true
              onClicked: topMiddlePane.onPage("button1");
          }
      }
      Image {
          id: button2
          source: "pict/button2Off.png"
          x: 210
          y: 0
           width: 111
           height: 52
          opacity: 1
      
          MouseArea {
              anchors.fill: parent
              hoverEnabled: true
              onClicked: topMiddlePane.onPage("button2");
          }
      
      
      
      function onPage(id){
          id.source = "pict/"+id+"On.png";
      }
      

      }@

      I want to switch source according to the value of my parameter (to onPage function).
      But my problem is that QML seeks id.source and not bouton1.source
      Do you have a solution?

      sorry for my English

      fmontigny

      "time is for all cannot simultaneously"

      [FRANCE]

      1 Reply Last reply Reply Quote 0
      • U
        ucomesdag last edited by

        Did you try: @onClicked: topMiddlePane.onPage(button2);@

        Write “Qt”, not “QT” (QuickTime).

        1 Reply Last reply Reply Quote 0
        • F
          fmontigny last edited by

          Great but now the id in the chain displays the error "QDeclarativeImage(0x31326e8)On.png"

          fmontigny

          "time is for all cannot simultaneously"

          [FRANCE]

          1 Reply Last reply Reply Quote 0
          • U
            ucomesdag last edited by

            That's because the id is not a string nor a regular variable.
            [quote]The id value is a special value for a QML object and should not be thought of as an ordinary object property; [/quote] "link to doc":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeintroduction.html#object-identifiers

            What might be a solution:
            @function onPage(id){
            id.source = (id == button1)? "pict/button1On.png": "pict/button2On.png";
            }@

            Write “Qt”, not “QT” (QuickTime).

            1 Reply Last reply Reply Quote 0
            • F
              fmontigny last edited by

              Yes but i have 20 buttons I can not make 20 times the process.

              Do you have a other solution? I may not be the right idea

              fmontigny

              "time is for all cannot simultaneously"

              [FRANCE]

              1 Reply Last reply Reply Quote 0
              • U
                ucomesdag last edited by

                Or else:
                @Image {
                id: button2
                property string name: "button2"
                source: "pict/button2Off.png"
                x: 210
                y: 0
                width: 111
                height: 52
                opacity: 1

                    MouseArea {
                            anchors.fill: parent
                            hoverEnabled: true
                            onClicked: topMiddlePane.onPage(id);
                    } 
                
                    function onPage(id){
                            id.source = "pict/"+id.name+"On.png";
                    }
                

                }@

                Write “Qt”, not “QT” (QuickTime).

                1 Reply Last reply Reply Quote 0
                • F
                  fmontigny last edited by

                  Good i love that.

                  Thx you and french kiss

                  fmontigny

                  "time is for all cannot simultaneously"

                  [FRANCE]

                  1 Reply Last reply Reply Quote 0
                  • U
                    ucomesdag last edited by

                    Pas de souci ;-)

                    Write “Qt”, not “QT” (QuickTime).

                    1 Reply Last reply Reply Quote 0
                    • U
                      ucomesdag last edited by

                      If it solved your issue, please don't forget to prepend [Solved] to the topic title.

                      Write “Qt”, not “QT” (QuickTime).

                      1 Reply Last reply Reply Quote 0
                      • N
                        njeisecke last edited by

                        You could also use the objectName property.

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