Search code examples
arrayslistviewcalendarqmlv-play

Setting calendar.selectedDate from the Selected Date of a SimpleRow


I am opening a calendar pop-up helpItem1 when selecting a date from a listView, which all works fine! What I am trying to do is set the calendar.selectedDate, to the date of the listView item each time a different list item is selected.

An extract of my array (userModel), which I use to create the listView is:

{"date":1551960000000, "name": user1},{"date":1552046400000, "name": user1},{"date":1552219200000, "name": user1}

A minimal section of my code is:

ListPage {
    id: userPage

    model: userModel

    delegate: SimpleRow {
                  id: userRow
                  width: userPage.width
                  text: modelData.name
                  detailText: new Date(modelData.date).getTime() 
                  onSelected: {
                      helpItem1.visible = true
                      calendar.selectedDate = new Date(modelData.date).getTime()
                 }            
             }

    Item { 
        id: helpItem1
        visible: false

        Rectangle {
            id: calendarPage
            anchors.centerIn: parent
            width: parent.width
            height: parent.height           

            AppButton {
                id: backButton
                onClicked:  {
                    helpItem1.visible = false
                }
                //Button used to close the `helpItem1` pop-up 
            }
            Flow {
                id: row
                Calendar {
                    id: calendar
                    focus: true
                    selectedDate: new Date() 
                }
                // Rest of calendar Code
            }
        }
    }
}

My question is:

How could I take the selected date of each SimpleRow item, and make that the calendar.selectedDate when the pop-up opens?

I have tried several variations of

SimpleRow.onSelected: {calendar.selectedDate = new Date(modelData.date).getTime()}

But nothing helps.


Solution

  • And within 9 minutes to tweaking, I figured it out:

    By removing the .getTime() from my onSelected {...} section it all works fine!

    onSelected: {
        helpItem1.visible = true
        calendar.selectedDate = new Date(modelData.date)
    }