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. How to show countdown timer on top of button
Forum Updated to NodeBB v4.3 + New Features

How to show countdown timer on top of button

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 395 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.
  • R Offline
    R Offline
    Reddy_12
    wrote on last edited by Reddy_12
    #1

    Hello,

    I am learning qml and i am trying to make an use case to run a count down timer on top of button in qml, the use case the i am trying to achieve in total is

    Use Case :
    When user presses on button in qml scene the color of the button has to be animated with red color and i have to run a count down timer on top of the button.

    Let's say when the Cam button is clicked, i want to change the color of Cam button and after color is applied i wanted to display a count down timer with some n value.

    Attaching the code i tried, any suggestions on how to achieve would be much appreciated.

    Code

    main.qml

    Window{
        width: 640
        height: 480
        visible: true
        color: "pink"
        title: qsTr("Button Panel")
        Body{
        }
        Guage{
        }
    }
    

    Body.qml

    import QtQuick 2.0
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.15
    
    Item {
        id:root
        width: 640
        height: 480
    
        property color bgColor
    
        signal repeaterbuttonpressed(int index,string buttonname)
        Rectangle{
            width: 250
            height: 600
            color: "beige"
            border.color: "black"
    
        }
        ListModel{
            id:listModel
            ListElement{
                name:"G"
            }
            ListElement{
                name:"M"
            }
            ListElement{
                name:"Mu"
            }
            ListElement{
                name:"Cam"
            }
            ListElement{
                name:"Im"
            }
            ListElement{
                name:"Ph"
            }
        }
    
        Flickable{
            x:scrollBar.x
            y:250
            anchors.fill: parent
            contentHeight: 2000
            Grid{
                id:scrollBar
                rows:8
                columns: 2
                spacing: 10
                Repeater{
                    model:listModel
                    Button{
                        id:btn
                        text:name
                        onClicked: {
                            repeaterbuttonpressed(index,name)
                        }
                    }
                }
            }
            ScrollBar.vertical:ScrollBar{
                id:vbar; active: true
            }
    }
    }
    

    Gauge.qml

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.15
    Item {
        Body{
            id:bodyId
            onRepeaterbuttonpressed: {
                console.log("inside the on repeater button pressed",index,buttonname)
                /*Among the above listed buttons in the ListElements when ever Cam button is pressed from Here i wanted to implement/execute code to  apply color to the specific Cam button at the same time wanted to start the count-down timer on top of the same Cam button */
            }
            function myRepeaterbuttonpressed(index,buttonname)
            {
                console.log("myrepeaterbutton "+buttonname)
                console.log("myrepeaterbutton "+index)
            }
            Component.onCompleted: {
                repeaterbuttonpressed.connect(myRepeaterbuttonpressed)
            }
        }
    }
    

    Attaching my expectation image for better understanding
    Expectation.jpg

    Thanks in advance,

    Regard's,
    R_12

    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