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. Animation in ListView
QtWS25 Last Chance

Animation in ListView

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 750 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.
  • T Offline
    T Offline
    Trikrista
    wrote on last edited by
    #1

    How to speed up the animation when changing currentIndex?
    How change currentIndex when scrolling the mouse?

    import QtQuick 2.4
    import QtQuick.Controls 1.2
    
    Rectangle {
        id: rootItem
    
        color: "lightgreen"
    
        ListModel {
            id: lModel
            ListElement {
                color: "red"
            }
            ListElement {
                color: "blue"
            }
            ListElement {
                color: "green"
            }
            ListElement {
                color: "yellow"
            }
            ListElement {
                color: "black"
            }
        }
    
        ListView {
            id: list
            width: parent.width
            height: btnLeft.y - btnLeft.height
            anchors.top: parent.top
            anchors.topMargin: btnLeft.height / 2
            snapMode: ListView.SnapOneItem
            orientation: ListView.Horizontal
    
            model: lModel
            delegate: Rectangle {
                width: rootItem.width
                height: btnLeft.y - btnLeft.height
                color: model.color
            }
        }
    
        Button {
            id: btnLeft
    
            width: parent.width / 3
            height: parent.height * 0.2
            anchors.bottom: parent.bottom
            anchors.bottomMargin: height * 0.2
            anchors.left: parent.left
            anchors.leftMargin: width / 2
            text: "<<"
            onClicked: {
                if (list.currentIndex > 0) {
                    list.currentIndex--
                }
            }
        }
    
        Button {
            id: btnRight
    
            width: parent.width / 3
            height: parent.height * 0.2
            anchors.bottom: parent.bottom
            anchors.bottomMargin: height * 0.2
            anchors.right: parent.right
            anchors.rightMargin: width / 2
            text: ">>"
            onClicked: {
                if (list.currentIndex < 4) {
                    list.currentIndex++
                }
            }
        }
    }
    

    I'm sorry for my bad English

    p3c0P 1 Reply Last reply
    0
    • T Trikrista

      How to speed up the animation when changing currentIndex?
      How change currentIndex when scrolling the mouse?

      import QtQuick 2.4
      import QtQuick.Controls 1.2
      
      Rectangle {
          id: rootItem
      
          color: "lightgreen"
      
          ListModel {
              id: lModel
              ListElement {
                  color: "red"
              }
              ListElement {
                  color: "blue"
              }
              ListElement {
                  color: "green"
              }
              ListElement {
                  color: "yellow"
              }
              ListElement {
                  color: "black"
              }
          }
      
          ListView {
              id: list
              width: parent.width
              height: btnLeft.y - btnLeft.height
              anchors.top: parent.top
              anchors.topMargin: btnLeft.height / 2
              snapMode: ListView.SnapOneItem
              orientation: ListView.Horizontal
      
              model: lModel
              delegate: Rectangle {
                  width: rootItem.width
                  height: btnLeft.y - btnLeft.height
                  color: model.color
              }
          }
      
          Button {
              id: btnLeft
      
              width: parent.width / 3
              height: parent.height * 0.2
              anchors.bottom: parent.bottom
              anchors.bottomMargin: height * 0.2
              anchors.left: parent.left
              anchors.leftMargin: width / 2
              text: "<<"
              onClicked: {
                  if (list.currentIndex > 0) {
                      list.currentIndex--
                  }
              }
          }
      
          Button {
              id: btnRight
      
              width: parent.width / 3
              height: parent.height * 0.2
              anchors.bottom: parent.bottom
              anchors.bottomMargin: height * 0.2
              anchors.right: parent.right
              anchors.rightMargin: width / 2
              text: ">>"
              onClicked: {
                  if (list.currentIndex < 4) {
                      list.currentIndex++
                  }
              }
          }
      }
      
      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @Trikrista

      How to speed up the animation when changing currentIndex?

      You can use positionViewAtIndex.

      How change currentIndex when scrolling the mouse?

      Use wheel even to get mouse scroll events. Then you have to find out if it goes up or down. It can be done using wheel.angleDelta.y. Scrolldown will give negative values. Then you have to just increment or decrement currentIndex depending on it.

      MouseArea {
          anchors.fill: parent
          onWheel: console.log(wheel.angleDelta.y)
      }
      

      157

      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