Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

QML Progress Spinner: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(Add "cleanup" tag)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
[[Category:Snippets]]
[[Category:Snippets]]
[[Category:HowTo]]
[[Category:HowTo]]

Revision as of 16:22, 3 March 2015

This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

[toc align_right="yes" depth="2"]

Progress Spinner

This snippet article shows how to make a nice little progress bar/activity spinner in QML. In builds upon the "Busy Indicator":http://developer.qt.nokia.com/wiki/Busy_Indicator_for_QML and "Simple Progress Bar":http://developer.qt.nokia.com/wiki/Simple_QML_Progress_Bar components and adds some nice little animations.

This Progress Spinner component is very easy to embed into your new and existing QML components. This is what it looks like (without the animations of course):

Progress Spinner

Implementation

import QtQuick 1.0
import ZapBsComponents 1.0

Item {
 id: progressSpinner
 property alias minimum: progress.minimum
 property alias maximum: progress.maximum
 property alias value: progress.value
 property alias progressWidth: progress.width
 property alias progressHeight: progress.height
 property color color: "#77B753"

BusyIndicator {
 id: busyIndicator
 anchors.fill: parent
 foregroundColor: progressSpinner.color
 opacity: ( value == maximum ) ? 0.0 : 1.0
 Behavior on opacity {
 NumberAnimation {
 duration: 100
 }
 }

RotationAnimation
 {
 target: busyIndicator
 property: "rotation" // Suppress a warning
 from: 0
 to: 360
 direction: RotationAnimation.Clockwise
 duration: 1000
 loops: Animation.Infinite
 running: progress.value < progress.maximum
 }
 }

SimpleProgressBar {
 id: progress
 anchors.centerIn: progressSpinner
 width: 2 * busyIndicator.actualInnerRadius - 12
 height: 12
 color: progressSpinner.color
 opacity: ( value  minimum || value  maximum ) ? 0.0 : 1.0
 Behavior on opacity {
 NumberAnimation {
 duration: 300
 }
 }

value: 35
 }
}

Usage

This little snippet demonstrates the fade in/out animations of the ProgressSpinner.—

import QtQuick 1.0

Rectangle {

id: root
width: 640
height: 360

ProgressSpinner {

id: progress
x: 10
y: 10
width: 100
height: 100

SequentialAnimation on value {

PauseAnimation { duration: 500 }
NumberAnimation { duration: 1500; from: 0; to: 100; }
PauseAnimation { duration: 500 }
loops: Animation.Infinite
}
}

}