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. Help with transitions
Qt 6.11 is out! See what's new in the release blog

Help with transitions

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 202 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
    RobM
    wrote on last edited by RobM
    #1

    Here I have some code which toggles between two y positions for this Rectangle:

        Rectangle {
            id: theRectangle
            height: 75
            width: 150
            y : open ? 0 : 110
            color: open ? "blue" : "red"
            property bool open: true
    
            Behavior on y {
                NumberAnimation {
                    easing.type: Easing.InOutQuad
                    duration: 1000
                }
            }
    
            MouseArea {
                anchors.fill: parent
                onClicked: theRectangle.open = !theRectangle.open
            }
        }
    

    now what I would like to do is alter it s/t instead of clicking to get the Rectangle to go from y = 110 back too y = 0, it will instead simply do that after a period of time has elapsed where the element hasn't been touched, but I am not sure how to go about doing that. My Timer doesn't seem to be working:

        Item {
            anchors.fill: parent
            
            Timer {
                interval: 5000; running: true; repeat: true
                onTriggered: if(theRectangle.open === true){theRectangle.open == false}
            }
    
            Rectangle {
                id: theRectangle
                height: 75
                width: 150
                y : open ? 0 : 110
                color: open ? "blue" : "red"
                property bool open: true
    
                Behavior on y {
                    NumberAnimation {
                        easing.type: Easing.InOutQuad
                        duration: 1000
                    }
                }
    
                MouseArea {
                    anchors.fill: parent
                    onClicked: theRectangle.open = !theRectangle.open
                }
            }
        }
    

    however, even if I can get it to work I need a way to toggle the time to reset if the user clicks the rectangle. Basically, I am attempting to model a menu that automatically hides if the user hasn't interacted with it in a given time duration.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RobM
      wrote on last edited by RobM
      #2

      Alright, it seems to be working like I want it with some small modifications:

          Item {
              anchors.fill: parent
              
              Timer {
                  id: timer
                  interval: 5000; running: true; repeat: true
                  onTriggered:
                  {
                      if(theRectangle.open === false)
                          theRectangle.open = !theRectangle.open
                  }
              }
              
              Rectangle {
                  id: theRectangle
                  height: 75
                  width: 150
                  y : open ? 0 : 110
                  color: open ? "blue" : "red"
                  property bool open: true
                  
                  Behavior on y {
                      NumberAnimation {
                          easing.type: Easing.InOutQuad
                          duration: 1000
                      }
                  }
                  
                  MouseArea {
                      anchors.fill: parent
                      onClicked:
                      {
                          if(theRectangle.open === true)
                              theRectangle.open = !theRectangle.open
                          timer.restart()
                      }
                  }
              }
          }
      
      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