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. Update Loaded Component in Stackview
Qt 6.11 is out! See what's new in the release blog

Update Loaded Component in Stackview

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 383 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.
  • J Offline
    J Offline
    Jmueller
    wrote on last edited by Jmueller
    #1

    Hello everybody,

    i try to update the text from a loaded component every second (the text is the current time).

    the qml Side is set by an StackView. In the Side a Loader loads the component which includes a text field.

    //    property string updateTime: secondValue
       Loader {
            id: firstBox
            sourceComponent: greybox
            height: 80
            anchors{
                top: mainText.bottom
                topMargin: 30
                left: parent.left
                leftMargin: 35
                right: parent.right
                rightMargin: 160
            }
            property string firstItem: qsTr("Date:")
            property string firstValue: currentDate()
            property string secondItem: qsTr("Time:")
            property string secondValue: currentTime()
            property string thirdItem: qsTr("Weekday:")
            property string thirdValue: currentWeekday()
        }
    	
    	
    	Timer{
            id: timer
            interval: 1000
            repeat: true
            running: true
            onTriggered:{
                  /*what i already try*/
    //            firstBox.active = false
    //            firstBox.active = true
    
    //            firstBox.source = ""
    //            firstBox.sourceComponent = greybox
    
    //            updateTime: currentTime()
    //            greybox.secondValue = currentTime()
    
    //            firstBox.sourceComponent = greybox
    
    /*hole side is reload so interactivity with the side is difficult*/
    //                pageStack.replace(pageStack.currentItem,"qrc:/qml_Sides/ThisSide.qml") 
    
    /*here i can see the timer is running*/
                console.debug("Hello World") 
            }
        }
    	
    	
    /*grey boxes*/
        Component{
            id: greybox
            Rectangle {
                color:"#E9EDF0"
                border.color: "#e7ebee"
                Rectangle {
                    color: "#d4d8db"
                    width: 1
                    height: parent.height
                    anchors.centerIn: parent
                }
                Text {
                    id: firstItemText
                    text: firstItem
                    font.pixelSize: 16
                    anchors {
                        left: parent.left
                        leftMargin: 10
                        top: parent.top
                        topMargin: 5
                    }
                }
                Text {
                    id: firstValueText
                    text: firstValue
                    font.pixelSize: 16
                    anchors {
                        left: parent.left
                        leftMargin: 190
                        top: firstItemText.top
                    }
                }
                Text {
                    id: secondItemText
                    text: secondItem
                    font.pixelSize: 16
                    anchors {
                        left: firstItemText.left
                        top: firstItemText.bottom
                        topMargin: 5
                    }
                }
                Text {
                    id: secondValueText
                    text: secondValue
                    font.pixelSize: 16
                    anchors {
                        left: firstValueText.left
                        top: secondItemText.top
                    }
                }
                Text {
                    id: thirdItemText
                    text: thirdItem
                    font.pixelSize: 16
                    anchors {
                        left: firstItemText.left
                        top: secondItemText.bottom
                        topMargin: 5
                    }
                }
                Text {
                    id: thirdValueText
                    text: thirdValue
                    font.pixelSize: 16
                    anchors {
                        left: firstValueText.left
                        top: thirdItemText.top
                    }
                }
            }
        }
    
        function currentDate(){
            return Qt.formatDate(new Date(),"dd-MM-yyyy");
        }
    
        function currentTime(){
            return Qt.formatTime(new Date(),"hh-mm-ss");
        }
    
        function currentWeekday(){
            var dayInTheWeek = new Date().getDay()
            var allWeekdays = [qsTr("Sunday"), qsTr("Monday"), qsTr("...."), qsTr("...."), qsTr("...."), qsTr("Friday"), qsTr(".....")];
            return allWeekdays[dayInTheWeek]
        }
    
    

    Is it possible to update components loaded in the Stackview?
    And when yes How?

    1 Reply Last reply
    0
    • IntruderExcluderI Offline
      IntruderExcluderI Offline
      IntruderExcluder
      wrote on last edited by
      #2

      Public properties/functions can be acessed via currentItem, e.g: stack.currentItem.myLabel = "Some text".

      1 Reply Last reply
      1
      • J Offline
        J Offline
        Jmueller
        wrote on last edited by
        #3

        Okay Thank you

        i solved it like you suggest:

            property alias setTime: firstBox.secondValue
            property alias setDate: firstBox.firstValue
            property alias setWeekday: firstBox.thirdValue
         Loader{
              ...
                property string firstValue: currentDate()
                property string secondValue: currentTime()
                property string thirdValue: currentWeekday()
        }
        
            Timer{
                id: timer
                interval: 999
                repeat: true
                running: true
                onTriggered:{
                    stack.currentItem.setTime = currentTime()
                    stack.currentItem.setDate = currentDate()
                    stack.currentItem.setWeekday = currentWeekday()
                }
            }
        
        
        
        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