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. [SOLVED][JS] id in parameter

[SOLVED][JS] id in parameter

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 3 Posters 2.8k 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.
  • F Offline
    F Offline
    fmontigny
    wrote on last edited by
    #1

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

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

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

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fmontigny
        wrote on last edited by
        #3

        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
        0
        • U Offline
          U Offline
          ucomesdag
          wrote on last edited by
          #4

          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
          0
          • F Offline
            F Offline
            fmontigny
            wrote on last edited by
            #5

            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
            0
            • U Offline
              U Offline
              ucomesdag
              wrote on last edited by
              #6

              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
              0
              • F Offline
                F Offline
                fmontigny
                wrote on last edited by
                #7

                Good i love that.

                Thx you and french kiss

                fmontigny

                "time is for all cannot simultaneously"

                [FRANCE]

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  ucomesdag
                  wrote on last edited by
                  #8

                  Pas de souci ;-)

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

                  1 Reply Last reply
                  0
                  • U Offline
                    U Offline
                    ucomesdag
                    wrote on last edited by
                    #9

                    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
                    0
                    • N Offline
                      N Offline
                      njeisecke
                      wrote on last edited by
                      #10

                      You could also use the objectName property.

                      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