Forums

OverviewFelgo 2 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.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support