Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › change text display on AppButton from array

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #20762

    Edward

    Hello!

    I want to add a third click option onto an app button, I can easily do this with 2 using an onClicked event but need an additional 3rd option,

    I am thinking something on the lines of

    property var dayCycleArr: ["Full Day", "Half Day (AM)", "Half Day (PM)" ]
    
        AppButton {
            id: dayCycle
            text:  dayCycleArr[0]
            z: 1
            anchors.bottom: parent.bottom
            anchors.right: parent.right
            onClicked: text = dayCycleArr ++
        }

     

     

    which I have tested and is not currently working, it displays the first index (which is specified as the initial text, but the text changes to NAN when I press it

     

    I want to use this button to assign a time details in my firebase write; so it’ll be the selected index is what writes.

    Should I be looping through this index to get this working? or how would I go about it?

     

    Thanks!

    #20763

    Günther
    Felgo Team

    Hi Edward,

    the increment operation on dayCycleArr does not make sense, you can not increment the array itself:

    dayCycleArr ++

    Instead, you should keep an additional property for the currently used array index, which you can increment:

    property var dayCycleArr: ["Full Day", "Half Day (AM)", "Half Day (PM)" ]
    property int currCycleIndex: 0
    
        AppButton {
            id: dayCycle
            text:  dayCycleArr[currCycleIndex]
            z: 1
            anchors.bottom: parent.bottom
            anchors.right: parent.right
            onClicked: {
              if(currCycleIndex ==  dayCycleArr.length - 1)
                currCycleIndex = 0; // start from beginning if at end of array
              else
                currCycleIndex++; // incremennt index otherwise
            }
        }

     

    #20764

    Javier

    Hello,

    You can do it in several ways. The following code works well.

        property var dayCycleArr: ["Full Day", "Half Day (AM)", "Half Day (PM)" ]
        property int index: 0
    
            AppButton {
                id:   dayCycle
                text: dayCycleArr[index]
                z: 1
                anchors.bottom: parent.bottom
                anchors.right: parent.right
                onClicked: index = (index + 1) % dayCycleArr.length
            }

     

    #20765

    Javier

    Hi Günther,

    I did not noticed before that you already replied :-).

    Kind regards,
    Javier.

Viewing 4 posts - 1 through 4 (of 4 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded