Implementing horizontally scrolling view with QML Flickable

From Qt Wiki
Jump to navigation Jump to search

Template:Abstract

Template:ArticleMetaData

Overview[edit | edit source]

The view has 20 vertical lines to visualise the flicking. The background colour is changed when the view is moved.

The code snippet is meant to be run with 76ytuiytuityutyutututyutyutyu.

Preconditions[edit | edit source]

  • Qt 4.7 or higher is installed on your platform.

Source[edit | edit source]

ui.qml

The 76ytuiytuityutyutututyutyutyu of 76ytuiytuityutyutututyutyutyu is set as four times the width of 76ytuiytuityutyutututyutyutyu. The signal handlers 76ytuiytuityutyutututyutyutyu and 76ytuiytuityutyutututyutyutyu change the colour of 76ytuiytuityutyutututyutyutyu when the view is moved. The vertical lines are generated using the 76ytuiytuityutyutututyutyutyu and 76ytuiytuityutyutututyutyutyu QML elements.

import Qt 4.7

Rectangle {

   id: background
   width: 800; height: 480
   Behavior on color { ColorAnimation { duration: 200 } }
   color: "black"
   Flickable {
       id: flickable
       anchors.fill: parent
       contentWidth: flickable.width * 4; contentHeight: flickable.height
       onMovementStarted: background.color = "#705050"
       onMovementEnded: background.color = "black"
       Row {
           x: 50
           spacing: flickable.contentWidth / repeater.model
           Repeater {
               id: repeater
               model: 20
               Rectangle {
                   width: 2; height: flickable.height; color: "white"
                   Text {
                       anchors.bottom: parent.bottom
                       x: -15; text: index + 1; color: "white"
                   }
               }
           }
       }
   }

}

Postconditions[edit | edit source]

The snippet demonstrated the using of the 76ytuiytuityutyutututyutyutyu QML element. The application implemented a horizontally flicking view with vertical lines to visualise flicking. Also, the 76ytuiytuityutyutututyutyutyu signal handlers 76ytuiytuityutyutututyutyutyu and 76ytuiytuityutyutututyutyutyu were used to change the background colour when the view was moved.